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 "command.h"
40 #include "mbbeagle.h"
41 #include "model.h"
42 #include "mcmc.h"
43 #include "sumpt.h"
44 #include "utils.h"
45 #if defined(__MWERKS__)
46 #include "SIOUX.h"
47 #endif
48 
49 #define NUMCOMMANDS                     62    /* The total number of commands in the program  */
50 #define NUMPARAMS                       280   /* The total number of parameters  */
51 #define PARAM(i, s, f, l)               p->string = s;    \
52                                         p->fp = f;        \
53                                         p->valueList = l; \
54                                         p++;
55 #define HIDE                            0
56 #define SHOW                            1
57 
58 /* Debugging options */
59 #undef SHOW_TOKENS
60 #undef ECHO_PROCESSED_COMMANDS
61 
62 /* Local function prototypes */
63 int      AddNameSet(NameSet **nameSetList, int numNameSets, char **nameSet, int numNames);
64 int      AddToSet (int i, int j, int k, int id);
65 int      AllocCharacters (void);
66 int      AllocMatrix (void);
67 int      AllocTaxa (void);
68 char     ChangeCase (char c);
69 int      CharacterCode (char ch, int *charCode, int chType);
70 int      CharacterNumber (int charCode, int chType);
71 int      CheckInitialPartitions (void);
72 int      Dex (TreeNode *p);
73 int      DoAbout (void);
74 int      DoAcknowledgments (void);
75 int      DoBeginParm (char *parmName, char *tkn);
76 int      DoBreaks (void);
77 int      DoBreaksParm (char *parmName, char *tkn);
78 int      DoCalibrate (void);
79 int      DoCalibrateParm (char *parmName, char *tkn);
80 int      DoCharset (void);
81 int      DoCharsetParm (char *parmName, char *tkn);
82 int      DoCharStat (void);
83 int      DoCitations (void);
84 int      DoConstraint (void);
85 int      DoConstraintParm (char *parmName, char *tkn);
86 int      DoCtype (void);
87 int      DoCtypeParm (char *parmName, char *tkn);
88 int      DoDelete (void);
89 int      DoDeleteParm (char *parmName, char *tkn);
90 int      DoDimensions (void);
91 int      DoDimensionsParm (char *parmName, char *tkn);
92 int      DoDisclaimer (void);
93 int      DoEndBlock (void);
94 int      DoExecuteParm (char *parmName, char *tkn);
95 int      DoExclude (void);
96 int      DoExcludeParm (char *parmName, char *tkn);
97 int      DoFormat (void);
98 int      DoFormatParm (char *parmName, char *tkn);
99 int      DoHelp (void);
100 int      DoHelpParm (char *parmName, char *tkn);
101 int      DoInclude (void);
102 int      DoIncludeParm (char *parmName, char *tkn);
103 int      DoLog (void);
104 int      DoLogParm (char *parmName, char *tkn);
105 int      DoManual (void);
106 int      DoManualParm (char *parmName, char *tkn);
107 int      DoMatrix (void);
108 int      DoMatrixParm (char *parmName, char *tkn);
109 int      DoNexusParm (char *parmName, char *tkn);
110 int      DoOutgroup (void);
111 int      DoOutgroupParm (char *parmName, char *tkn);
112 int      DoPairs (void);
113 int      DoPairsParm (char *parmName, char *tkn);
114 int      DoPartition (void);
115 int      DoPartitionParm (char *parmName, char *tkn);
116 int      DoRestore (void);
117 int      DoRestoreParm (char *parmName, char *tkn);
118 int      DoSet (void);
119 int      DoSetParm (char *parmName, char *tkn);
120 int      DoShowBeagle (void);
121 int      DoShowMatrix (void);
122 int      DoShowUserTrees (void);
123 int      DoSpeciespartition (void);
124 int      DoSpeciespartitionParm (char *parmName, char *tkn);
125 int      DoTaxaset (void);
126 int      DoTaxasetParm (char *parmName, char *tkn);
127 int      DoTaxaStat (void);
128 int      DoTaxlabels (void);
129 int      DoTaxlabelsParm (char *parmName, char *tkn);
130 int      DoTranslate (void);
131 int      DoTranslateParm (char *parmName, char *tkn);
132 int      DoTree (void);
133 int      DoTreeParm (char *parmName, char *tkn);
134 int      DoUserTree (void);
135 int      DoUserTreeParm (char *parmName, char *tkn);
136 int      DoVersion (void);
137 int      FindValidParam (char *tk, int *numMatches);
138 int      FreeCharacters (void);
139 int      FreeMatrix (void);
140 int      FreeTaxa (void);
141 int      GetNumPartDivisions (int n);
142 int      GetUserHelp (char *helpTkn);
143 int      IsAmbig (int charCode, int dType);
144 int      IsMissing (int charCode, int dType);
145 int      MBResID (char nuc);
146 int      NucID (char nuc);
147 void     PrintSettings (char *command);
148 void     PrintYesNo (int yn, char s[4]);
149 int      ProtID (char aa);
150 int      SetPartition (int part);
151 int      SetSpeciespartition (int part);
152 int      SetTaxaFromTranslateTable (void);
153 int      StandID (char nuc);
154 void     WhatVariableExp (BitsLong exp, char *st);
155 MrBFlt   WhichCont (int x);
156 
157 /* globals */
158 int             autoClose;             /* autoclose                                     */
159 int             autoOverwrite;         /* Overwrite or append outputfiles when nowarnings=yes */
160 Calibration     *calibrationPtr;       /* ptr to calibration being set                  */
161 CharInformation *charInfo;             /* holds critical information about characters   */
162 BitsLong        **charSet;             /* holds information about defined charsets      */
163 char            **charSetNames;        /* holds names of character sets                 */
164 Comptree        comptreeParams;        /* holds parameters for comparetree command      */
165 char            **constraintNames;     /* holds names of constraints                    */
166 int             dataType;              /* type of data                                  */
167 Calibration     defaultCalibration;    /* default calibration                           */
168 BitsLong        **definedConstraint;          /* bitfields representing taxa sets of defined constraints                                             */
169 BitsLong        **definedConstraintTwo;       /* bitfields representing second taxa sets of defined constraints (used for PARTIAL constraints)       */
170 BitsLong        **definedConstraintPruned;    /* bitfields representing taxa sets of defined constraints after delited taxa are removed              */
171 BitsLong        **definedConstraintTwoPruned; /* bitfields representing second taxa sets of defined constraints for PARTIAL constraints after delited*/
172                                               /* taxa are removed and for NEGATIVE constraint it contains complements of definedConstraintPruned     */
173 int             echoMB;                /* flag used by Manual to prevent echoing        */
174 BitsLong        expecting;             /* variable denoting expected token type         */
175 int             foundNewLine;          /* whether a new line has been found             */
176 int             inComment;             /* flag for whether input stream is commented    */
177 int             inComparetreeCommand;  /* flag set whenever you enter comparetree cmd   */
178 int             inferAncStates;        /* should ancestral states be inferred (y/n)     */
179 int             inferSiteOmegas;       /* should site omegas be inferred (y/n)          */
180 int             inferSiteRates;        /* should site rates be inferred (y/n)           */
181 int             inMrbayesBlock;        /* flag for whether we are in a mrbayes block    */
182 int             inSumtCommand;         /* flag set whenever you enter sumt cmd          */
183 int             inTreesBlock;          /* flag for whether we are in a trees block      */
184 int             inValidCommand;        /* a useful flag set whenever you enter a cmd    */
185 int             isInAmbig, isInPoly;   /* flags whether we are within () or {}          */
186 int             isTaxsetDef;           /* is a taxon set defined                        */
187 int             isTranslateDef;        /* is a translation block defined                */
188 int             isTranslateDiff;       /* is translate different from current taxaset?  */
189 char            logFileName[100];      /* name of the log file                          */
190 int             logToFile;             /* should screen output be logged to a file      */
191 FILE            *logFileFp;            /* file pointer to log file                      */
192 int             longIntegerSize;       /* size of an unsigned integer                   */
193 char            manFileName[100];      /* name of the file for the command help info    */
194 int             *matrix;               /* matrix containing original data               */
195 int             matrixHasPoly;         /* flag for whether matrix has polymorphisms     */
196 int             memAllocs[NUM_ALLOCS]; /* allocated memory flags                        */
197 int             mode;                  /* mode of program (interactive/noninteractive)  */
198 Calibration     *nodeCalibration;      /* holds information about node calibrations     */
199 int             noWarn;                /* no warnings on overwriting files              */
200 int             numChar;               /* number of characters in character matrix      */
201 int             numCharSets;           /* number of character sets                      */
202 int             numComments;           /* counts how deeply nested a comment is         */
203 int             numDefinedConstraints; /* number of constraints defined                 */
204 int             numDefinedPartitions;  /* number of partitions defined                  */
205 int             numDefinedSpeciespartitions;  /* number of speciespartitions defined    */
206 int             numNamedTaxa;          /* number of named taxa during parsing of cmd    */
207 int             numOpenExeFiles;       /* number of execute files open                  */
208 int             numSpecies;            /* number of species in current speciespartition */
209 int             numTaxa;               /* number of taxa in character matrix            */
210 int             numTaxaSets;           /* number of taxa sets                           */
211 int             numTranslates;         /* number of taxa in active translate block      */
212 int             outGroupNum;           /* number of outgroup taxon                      */
213 ParmInfo        paramTable[NUMPARAMS]; /* information on parameters                     */
214 char            **partitionNames;      /* hold names of partitions (first is "default") */
215 int             **partitionId;         /* holds information about defined partitions    */
216 int             partitionNum;          /* index of current partition                    */
217 Plot            plotParams;            /* holds parameters for plot command             */
218 int             precision;             /* precision of samples and summary stats        */
219 int             quitOnError;           /* quit on error?                                */
220 int             replaceLogFile;        /* should logfile be replace/appended to         */
221 int             scientific;            /* use scientific format for samples ?           */
222 char            spacer[10];            /* holds blanks for printing indentations        */
223 NameSet         *speciesNameSets;      /* hold species name sets, one for each speciespartition     */
224 int             **speciespartitionId;  /* holds info about defined speciespartitions    */
225 char            **speciespartitionNames;    /* hold names of speciespartitions (first is "default") */
226 int             speciespartitionNum;   /* index of current speciespartition             */
227 Sump            sumpParams;            /* holds parameters for sump command             */
228 Sumt            sumtParams;            /* holds parameters for sumt command             */
229 Sumss           sumssParams;           /* holds parameters for sumss command            */
230 TaxaInformation *taxaInfo;             /* holds critical information about taxa         */
231 char            **taxaNames;           /* holds name of taxa                            */
232 BitsLong        **taxaSet;             /* holds information about defined taxasets      */
233 char            **taxaSetNames;        /* holds names of taxa sets                      */
234 int             *tempActiveConstraints;/* temporarily holds active constraints size allcated        */
235 enum ConstraintType  *definedConstraintsType;  /* Store type of constraint              */
236 int             *tempSet;              /* temporarily holds defined set                 */
237 int             *tempSetNeg;           /* holds bitset of negative set of taxa for partial constraint*/
238 int             theAmbigChar;          /* int containing ambiguous character            */
239 Calibration     *tipCalibration;       /* holds information about node calibrations     */
240 char            **transFrom;           /* translation block information                 */
241 char            **transTo;             /* translation block information                 */
242 int             userBrlensDef;         /* are the branch lengths on user tree defined   */
243 
244 #if defined (BEAGLE_ENABLED)
245 int             tryToUseBEAGLE;        /* try to use the BEAGLE library                 */
246 int             beagleScalingScheme;   /* BEAGLE dynamic scaling                        */
247 int             beagleScalingFrequency;/* BEAGLE dynamic scaling frequency              */
248 long            beagleFlags;           /* BEAGLE required resource flags                */
249 int             beagleResourceNumber;  /* BEAGLE resource number                        */
250 int             *beagleResource;       /* BEAGLE resource choice list                   */
251 int             beagleResourceCount;   /* BEAGLE resource choice list length            */
252 int             beagleInstanceCount;   /* total number of BEAGLE instances              */
253 #if defined (BEAGLE_V3_ENABLED)
254 int             beagleThreadCount;     /* max number of BEAGLE CPU threads              */
255 int             beagleAllFloatTips;    /* use floating-point represantion for all tips  */
256 #endif
257 #endif
258 
259 /* local (to this file) */
260 char            *tokenP, token[CMD_STRING_LENGTH], *cmdStr=NULL;
261 Calibration     defaultCalibration = {
262                     "Unconstrained",      /* name */
263                     unconstrained,        /* prior */
264                     { -1.0, -1.0, -1.0 }, /* priorParams */
265                     NULL,                 /* LnPriorProb */
266                     NULL,                 /* LnPriorRatio */
267                     -1.0,                 /* min */
268                     -1.0                  /* max */
269                 };
270 
271 CmdType     commands[] =
272             {
273             /*  Information on commands initialization:
274 
275                     1 = Command number (cmdNumber)
276                     2 = Command name (string)
277                     3 = Special command (YES/NO) (specialCmd)
278                     4 = Pointer to finishing function (fp)
279                     5 = Number of valid parameters (numParms)
280                     6 = List of valid parameters (parmList)
281                     7 = Expecting (2^TokenType) (expect) (PARAMETER = 4; SEMICOLON = 32; ALPHA = 16384;
282                         ALPHA | QUESTIONMARK | DASH | NUMBER | ASTERISK | EXCLAMATIONMARK | PERCENT | WEIRD | SEMICOLON = 11715360;
283                         ALPHA | QUESTIONMARK | DASH | NUMBER | ASTERISK | EXCLAMATIONMARK | PERCENT | WEIRD | VERTICALBAR | SEMICOLON | LEFTPAR | RIGHTPAR | LEFTCURL | RIGHTCURL = 649252640;
284                         PARAMETER | SEMICOLON = 36; NUMBER | ALPHA = 49152; ALPHA | SEMICOLON = 16416; EQUALSIGN = 8; NUMBER = 32768)
285                     8 = Description of the command (cmdDescription)
286                     9 = Where should the command be used (cmdUse) (IN_CMD = used from command line or mrbayes block; IN_FILE = used in data block or in tree block)
287                    10 = Should the command be shown when "help" is typed (hiding).
288 
289               #1                 #2   #3                 #4  #5                                                                                                #6        #7                                                            #8       #9   #10
290              -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
291             {  0,               "#",  NO,              NULL,  1,                                                                                              {0},        4,                                                           "", IN_FILE, HIDE },
292             {  1,           "About",  NO,           DoAbout,  0,                                                                                             {-1},       32,                                      "Describes the program",  IN_CMD, SHOW },
293             {  2, "Acknowledgments",  NO, DoAcknowledgments,  0,                                                                                             {-1},       32,                              "Shows program acknowledgments",  IN_CMD, SHOW },
294             {  3,           "Begin",  NO,              NULL,  6,                                                                              {1,2,3,201,226,227},        4,                         "Denotes beginning of block in file", IN_FILE, SHOW },
295             {  4,       "Calibrate",  NO,       DoCalibrate,  1,                                                                                            {119},        4,               "Assigns dates to terminals or interior nodes",  IN_CMD, SHOW },
296             {  5,         "Charset",  NO,         DoCharset,  1,                                                                                             {15},        4,                          "Assigns a group of sites to a set",  IN_CMD, SHOW },
297             {  6,        "Charstat",  NO,        DoCharStat,  0,                                                                                             {-1},       32,                                 "Shows status of characters",  IN_CMD, SHOW },
298             {  7,       "Citations",  NO,       DoCitations,  0,                                                                                             {-1},       32,                   "Citation of program, models, and methods",  IN_CMD, SHOW },
299             {  8,     "Comparetree",  NO,     DoCompareTree,  7,                                                                    {127,128,129,130,221,222,223},       36,                     "Compares the trees from two tree files",  IN_CMD, SHOW },
300             {  9,      "Constraint",  NO,      DoConstraint,  1,                                                                                             {66},        4,                      "Defines a constraint on tree topology",  IN_CMD, SHOW },
301             { 10,           "Ctype",  NO,           DoCtype,  1,                                                                                             {65},        4,                        "Assigns ordering for the characters",  IN_CMD, SHOW },
302             { 11,      "Databreaks", YES,          DoBreaks,  1,                                                                                             {93},    32768,           "Defines data breaks for autodiscrete gamma model",  IN_CMD, SHOW },
303             { 12,          "Delete", YES,          DoDelete,  1,                                                                                             {47},    49152,                             "Deletes taxa from the analysis",  IN_CMD, SHOW },
304             { 13,      "Dimensions",  NO,      DoDimensions,  2,                                                                                            {4,5},        4,                           "Defines size of character matrix", IN_FILE, SHOW },
305             { 14,      "Disclaimer",  NO,      DoDisclaimer,  0,                                                                                             {-1},       32,                               "Describes program disclaimer",  IN_CMD, SHOW },
306             { 15,             "End",  NO,        DoEndBlock,  0,                                                                                             {-1},       32,                             "Denotes end of a block in file", IN_FILE, SHOW },
307             { 16,        "Endblock",  NO,        DoEndBlock,  0,                                                                                             {-1},       32,                 "Alternative way of denoting end of a block", IN_FILE, SHOW },
308             { 17,         "Exclude", YES,         DoExclude,  1,                                                                                             {45},    49152,                           "Excludes sites from the analysis",  IN_CMD, SHOW },
309             { 18,         "Execute", YES,         DoExecute,  1,                                                                                             {12},    16384,                                            "Executes a file",  IN_CMD, SHOW },
310             { 19,          "Format",  NO,          DoFormat,  7,                                                                             {6,7,8,9,10,219,220},        4,                     "Defines character format in data block", IN_FILE, SHOW },
311             { 20,            "Help", YES,            DoHelp,  1,                                                                                             {50},    16416,                  "Provides detailed description of commands",  IN_CMD, SHOW },
312             { 21,         "Include", YES,         DoInclude,  1,                                                                                             {46},    49152,                                             "Includes sites",  IN_CMD, SHOW },
313             { 22,            "Link",  NO,            DoLink, 30,  {55,56,57,58,59,60,61,62,63,72,73,74,75,76,105,118,193,194,195,196,197,242,243,252,253,255,256,
314                                                                                                                                                      270,273,274},        4,               "Links parameters across character partitions",  IN_CMD, SHOW },
315             { 23,             "Log",  NO,             DoLog,  5,                                                                                 {85,86,87,88,89},        4,                               "Logs screen output to a file",  IN_CMD, SHOW },
316             { 24,            "Lset",  NO,            DoLset, 18,                                     {28,29,30,31,32,33,34,40,51,52,53,90,91,131,188,189,276,277},        4,                "Sets the parameters of the likelihood model",  IN_CMD, SHOW },
317             { 25,          "Manual",  NO,          DoManual,  1,                                                                                            {126},       36,                  "Prints a command reference to a text file",  IN_CMD, SHOW },
318             { 26,          "Matrix", YES,          DoMatrix,  1,                                                                                             {11},649252640,                 "Defines matrix of characters in data block", IN_FILE, SHOW },
319             { 27,            "Mcmc",  NO,            DoMcmc, 46,  {17,18,19,20,21,22,23,24,25,26,27,84,98,112,113,114,115,116,132,142,143,144,148,149,150,151,152,
320                                                                                      153,154,155,156,157,158,159,160,166,169,190,191,198,199,200,202,213,214,215},       36,                   "Starts Markov chain Monte Carlo analysis",  IN_CMD, SHOW },
321             { 28,           "Mcmcp",  NO,           DoMcmcp, 46,  {17,18,19,20,21,22,23,24,25,26,27,84,98,112,113,114,115,116,132,142,143,144,148,149,150,151,152,
322                                                                                      153,154,155,156,157,158,159,160,166,169,190,191,198,199,200,202,213,214,215},        4,     "Sets parameters of a chain (without starting analysis)",  IN_CMD, SHOW },
323             { 29,        "Outgroup", YES,        DoOutgroup,  1,                                                                                             {78},    49152,                                     "Changes outgroup taxon",  IN_CMD, SHOW },
324             { 30,           "Pairs", YES,           DoPairs,  1,                                                                                             {92},    32768,        "Defines nucleotide pairs (doublets) for stem models",  IN_CMD, SHOW },
325             { 31,       "Partition",  NO,       DoPartition,  1,                                                                                             {16},        4,                              "Assigns a character partition",  IN_CMD, SHOW },
326             { 32,            "Plot",  NO,            DoPlot,  6,                                                                        {106,107,108,109,224,225},       36,                        "Plots parameters from MCMC analysis",  IN_CMD, SHOW },
327             { 33,           "Prset",  NO,           DoPrset, 43,  {35,36,37,38,39,41,42,43,44,54,64,67,68,69,70,71,77,100,101,102,103,104,110,111,117,120,121,133,
328                                                                                                  168,172,173,174,183,184,185,218,241,246,247,251,254,269,271,272},        4,                         "Sets the priors for the parameters",  IN_CMD, SHOW },
329             { 34,         "Propset",  NO,         DoPropset,  1,                                                                                            {186},        4,          "Sets proposal probabilities and tuning parameters",  IN_CMD, SHOW },
330             { 35,            "Quit",  NO,            DoQuit,  0,                                                                                             {-1},       32,                                          "Quits the program",  IN_CMD, SHOW },
331             { 36,          "Report",  NO,          DoReport,  9,                                                            {122,123,124,125,134,135,136,192,217},        4,                 "Controls how model parameters are reported",  IN_CMD, SHOW },
332             { 37,         "Restore", YES,         DoRestore,  1,                                                                                             {48},    49152,                                              "Restores taxa",  IN_CMD, SHOW },
333             { 38,             "Set",  NO,             DoSet, 24,   {13,14,94,145,170,171,179,181,182,216,229,233,234,235,236,237,238,239,240,245,268,275,278,279},        4,      "Sets run conditions and defines active data partition",  IN_CMD, SHOW },
334             { 39,      "Showbeagle",  NO,      DoShowBeagle,  0,                                                                                             {-1},       32,                            "Show available BEAGLE resources",  IN_CMD, SHOW },
335             { 40,      "Showmatrix",  NO,      DoShowMatrix,  0,                                                                                             {-1},       32,                             "Shows current character matrix",  IN_CMD, SHOW },
336             { 41,   "Showmcmctrees",  NO,   DoShowMcmcTrees,  0,                                                                                             {-1},       32,                          "Shows trees used in mcmc analysis",  IN_CMD, SHOW },
337             { 42,       "Showmodel",  NO,       DoShowModel,  0,                                                                                             {-1},       32,                                       "Shows model settings",  IN_CMD, SHOW },
338             { 43,       "Showmoves",  NO,       DoShowMoves,  1,                                                                                            {180},       36,                              "Shows moves for current model",  IN_CMD, SHOW },
339             { 44,      "Showparams",  NO,      DoShowParams,  0,                                                                                             {-1},       32,                          "Shows parameters in current model",  IN_CMD, SHOW },
340             { 45,   "Showusertrees",  NO,   DoShowUserTrees,  0,                                                                                             {-1},       32,                                   "Shows user-defined trees",  IN_CMD, SHOW },
341             { 46,"Speciespartition",  NO,DoSpeciespartition,  1,                                                                                            {244},        4,                   "Defines a partition of tips into species",  IN_CMD, SHOW },
342             { 47,              "Ss",  NO,              DoSs, 50,  {17,18,19,20,21,22,23,24,25,26,27,84,98,112,113,114,115,116,132,142,143,144,148,149,150,151,152,
343                                                                      153,154,155,156,157,158,159,160,166,169,190,191,198,199,200,202,213,214,215,248,249,250,257},       36,                             "Starts stepping-stone sampling",  IN_CMD, SHOW },
344             { 48,             "Ssp",  NO,             DoSsp, 50,  {17,18,19,20,21,22,23,24,25,26,27,84,98,112,113,114,115,116,132,142,143,144,148,149,150,151,152,
345                                                                      153,154,155,156,157,158,159,160,166,169,190,191,198,199,200,202,213,214,215,248,249,250,257},       36,"Sets parameters of stepping-stone analysis (without starting)",IN_CMD, SHOW },
346             { 49,       "Startvals",  NO,       DoStartvals,  1,                                                                                            {187},        4,                         "Sets starting values of parameters",  IN_CMD, SHOW },
347             { 50,            "Sump",  NO,            DoSump, 13,                                              {96,97,137,138,139,140,141,161,162,178,211,212,231},       36,                   "Summarizes parameters from MCMC analysis",  IN_CMD, SHOW },
348             { 51,           "Sumss",  NO,           DoSumSs, 10,                                                        {258,259,260,261,262,263,264,265,266,267},       36,         "Summarizes parameters from stepping-stone analysis",  IN_CMD, SHOW },
349             { 52,            "Sumt",  NO,            DoSumt, 21,                {80,81,82,95,146,147,163,164,165,167,175,177,204,205,206,207,208,209,210,230,232},       36,                        "Summarizes trees from MCMC analysis",  IN_CMD, SHOW },
350             { 53,        "Taxastat",  NO,        DoTaxaStat,  0,                                                                                             {-1},       32,                                       "Shows status of taxa",  IN_CMD, SHOW },
351             { 54,          "Taxset",  NO,         DoTaxaset,  1,                                                                                             {49},        4,                           "Assigns a group of taxa to a set",  IN_CMD, SHOW },
352             { 55,       "Taxlabels", YES,       DoTaxlabels,  1,                                                                                            {228},    49152,                                       "Defines taxon labels", IN_FILE, SHOW },
353             { 56,       "Translate", YES,       DoTranslate,  1,                                                                                             {83},    49152,                         "Defines alternative names for taxa", IN_FILE, SHOW },
354             { 57,            "Tree",  NO,            DoTree,  1,                                                                                             {79},        4,                                             "Defines a tree", IN_FILE, SHOW },
355             { 58,          "Unlink",  NO,          DoUnlink, 30,  {55,56,57,58,59,60,61,62,63,72,73,74,75,76,105,118,193,194,195,196,197,242,243,252,253,255,256,
356                                                                                                                                                      270,273,274},        4,             "Unlinks parameters across character partitions",  IN_CMD, SHOW },
357             { 59,        "Usertree", YES,        DoUserTree,  1,                                                                                            {203},        8,                                 "Defines a single user tree",  IN_CMD, HIDE },
358             { 60,         "Version",  NO,         DoVersion,  0,                                                                                             {-1},       32,                                      "Shows program version",  IN_CMD, SHOW },
359             { 61,      "Compareref",  NO,     DoCompRefTree,  7,                                                                    {127,128,129,130,221,222,223},       36,                     "Compares the tree to the reference trees",  IN_CMD, HIDE },
360             /* NOTE: If you add a command here, make certain to change NUMCOMMANDS (above, in this file) appropriately! */
361             { 999,             NULL,  NO,              NULL,  0,                                                                                             {-1},       32,                                                           "",  IN_CMD, HIDE }
362             };
363 int                 inDataBlock, inForeignBlock, isInterleaved, isFirstMatrixRead, isFirstInterleavedBlock,
364                     taxonCount, fromI, toJ, everyK, foundDash, foundSlash, foundFirst, isMixed, whichPartition,
365                     isNegative, numDivisions, charOrdering, foundExp, foundColon, isFirstNode, nextAvailableNode,
366                     pairId, firstPair, inTaxaBlock, inCharactersBlock, foundEqual;
367 char                gapId, missingId, matchId, tempSetName[100], **tempNames;
368 CmdType             *commandPtr; /* Points to the commands array entry which corresponds to currently processed command */
369 ParmInfoPtr         paramPtr;    /* Points to paramTable table array entry which corresponds to currently processed parameter of current command */
370 TreeNode            *pPtr, *qPtr;
371 
372 enum ConstraintType constraintType; /* Used only in processing of constraint command to indicate the type of constraint */
373 
374 
AddToGivenSet(int i,int j,int k,int id,int * Set)375 int AddToGivenSet (int i, int j, int k, int id, int *Set)
376 {
377     int     m, n;
378 
379     if (id <= 0)
380         {
381         MrBayesPrint ("%s   The id for a temporary set should be greater than 0\n", spacer);
382         return (ERROR);
383         }
384 
385     if (i < 0 && j < 0)
386         return (ERROR);
387     else if (i < 0 && j >= 0)
388         return (ERROR);
389     else if (i >= 0 && j < 0)
390         {
391         if (k >= 0)
392             return (ERROR);
393         else
394             {
395             if (Set[i] != 0)
396                 {
397                 MrBayesPrint ("%s   Character %d defined more than once\n", spacer, i+1);
398                 return (ERROR);
399                 }
400             Set[i] = id;
401             }
402         }
403     else if (i >= 0 && j >= 0)
404         {
405         if (k < 0)
406             {
407             for (m=i; m<=j; m++)
408                 {
409                 if (Set[m] != 0)
410                     {
411                     MrBayesPrint ("%s   Character %d defined more than once\n", spacer, m+1);
412                     return (ERROR);
413                     }
414                 Set[m] = id;
415                 }
416             }
417         else
418             {
419             n = k;
420             for (m=i; m<=j; m++)
421                 {
422                 if (n % k == 0)
423                     {
424                     if (Set[m] != 0)
425                         {
426                         MrBayesPrint ("%s   Character %d defined more than once\n", spacer, m+1);
427                         return (ERROR);
428                         }
429                     Set[m] = id;
430                     }
431                 n++;
432                 }
433             }
434         }
435 
436     return (NO_ERROR);
437 
438 }
439 
440 
AddToSet(int i,int j,int k,int id)441 int AddToSet (int i, int j, int k, int id)
442 {
443     return AddToGivenSet (i, j, k,id, tempSet);
444 }
445 
446 
447 /* AddNameSet: Push a name set onto the end of a list of name sets, with reallocation
448       of list to hold the extra element. The calling function needs to keep track of
449       the counter holding the length of the list. */
AddNameSet(NameSet ** nameSetList,int numNameSets,char ** nameSet,int numNames)450 int AddNameSet (NameSet **nameSetList, int numNameSets, char **nameSet, int numNames)
451 {
452     int     i;
453 
454     (*nameSetList) = (NameSet*) SafeRealloc ((void*)(*nameSetList), ((size_t)numNameSets+1)*sizeof(NameSet));
455 
456     (*nameSetList)[numNameSets].names    = NULL;
457     (*nameSetList)[numNameSets].numNames = numNames;
458 
459     for (i=0; i<numNames; i++)
460         AddString(&((*nameSetList)[numNameSets].names), i, nameSet[i]);
461 
462     return NO_ERROR;
463 }
464 
465 
466 /* AddString: Push a string onto the end of a list, with reallocation of list
467       to hold the extra element. The calling function needs to keep track of
468       the counter holding the length of the list. */
AddString(char *** list,int len,char * token)469 int AddString (char ***list, int len, char *token)
470 {
471     (*list) = (char **) SafeRealloc ((void *)(*list), ((size_t)len+1)*sizeof(char*));
472     if (!(*list))
473         return ERROR;
474 
475     (*list)[len] = (char *) SafeCalloc ((strlen(token)+1), sizeof(char));
476     if (!(*list)[len])
477         return ERROR;
478 
479     strcpy ((*list)[len], token);
480 
481     return NO_ERROR;
482 }
483 
484 
AllocCharacters(void)485 int AllocCharacters (void)
486 {
487     int     i, tempSetSize;
488 
489     if (memAllocs[ALLOC_MATRIX] == YES)
490         goto errorExit;
491     matrix = (int *) SafeMalloc((size_t)numTaxa * (size_t)numChar * sizeof(int));
492     if (!matrix)
493         {
494         MrBayesPrint ("%s   Problem allocating matrix (%d)\n", spacer, numTaxa * numChar * sizeof(int));
495         goto errorExit;
496         }
497     for (i=0; i<numTaxa * numChar; i++)
498         matrix[i] = 0;
499     memAllocs[ALLOC_MATRIX] = YES;
500 
501     if (memAllocs[ALLOC_CHARINFO] == YES)
502         goto errorExit;
503     charInfo = (CharInformation *) SafeMalloc ((size_t)numChar * sizeof(CharInformation));
504     if (!charInfo)
505         {
506         MrBayesPrint ("%s   Problem allocating charInfo (%d)\n", spacer, numChar * sizeof(CharInformation));
507         goto errorExit;
508         }
509     for (i=0; i<numChar; i++)
510         {
511         charInfo[i].isExcluded = NO;
512         charInfo[i].numStates = 0;
513         charInfo[i].charType = 0;
514         charInfo[i].isMissAmbig = NO;
515         charInfo[i].ctype = UNORD;
516         charInfo[i].charId = 0;
517         charInfo[i].pairsId = 0;
518         charInfo[i].bigBreakAfter = NO;
519         }
520     memAllocs[ALLOC_CHARINFO] = YES;
521 
522     if (memAllocs[ALLOC_CHARSETS] == YES)
523         goto errorExit;
524     charSetNames = NULL;
525     charSet = NULL;
526     numCharSets = 0;
527     memAllocs[ALLOC_CHARSETS] = YES;    /* safe to do free */
528 
529     if (memAllocs[ALLOC_PARTITIONS] == YES)
530         goto errorExit;
531     partitionNames = NULL;
532     partitionId = (int**) SafeMalloc ((size_t)numChar * sizeof(int*));
533     for (i=0; i<numChar; i++)
534         partitionId[i] = (int *) SafeMalloc (sizeof(int));
535     numDefinedPartitions = 0;   /* number of defined partitions */
536     memAllocs[ALLOC_PARTITIONS] = YES;  /* safe to do free */
537 
538     if (memAllocs[ALLOC_PARTITIONVARS] == YES)
539         goto errorExit;
540     numVars           = NULL;
541     tempLinkUnlinkVec = NULL;
542     activeParts       = NULL;
543     tempLinkUnlinkVec = NULL;
544     tempNum           = NULL;
545     linkTable[0]      = NULL;
546     tempLinkUnlink[0] = NULL;
547     for (i=0; i<NUM_LINKED; i++)
548         {
549         linkTable[i]      = NULL;
550         tempLinkUnlink[i] = NULL;
551         activeParams[i]   = NULL;
552         }
553     memAllocs[ALLOC_PARTITIONVARS] = YES;
554 
555     if (memAllocs[ALLOC_TMPSET] == NO)
556         goto errorExit;
557     if (numChar > numTaxa)
558         tempSetSize = numChar;
559     else
560         tempSetSize = numTaxa;
561     tempSet = (int *) SafeRealloc ((void *)tempSet, (size_t)tempSetSize * sizeof(int));
562     tempSetNeg = (int *) SafeRealloc ((void *)tempSetNeg, (size_t)tempSetSize * sizeof(int));
563     if (!tempSet || !tempSetNeg)
564         {
565         MrBayesPrint ("%s   Problem reallocating tempSet (%d)\n", spacer, tempSetSize * sizeof(int));
566         goto errorExit;
567         }
568 
569     MrBayesPrint ("%s   Allocated matrix\n", spacer);
570     return (NO_ERROR);
571 
572     errorExit:
573         MrBayesPrint ("%s   Problem allocating matrix\n", spacer);
574         FreeMatrix();
575         return (ERROR);
576 }
577 
578 
AllocMatrix(void)579 int AllocMatrix (void)
580 {
581     if (memAllocs[ALLOC_TAXA] == NO && AllocTaxa() == ERROR)
582         return ERROR;
583     else
584         return (AllocCharacters());
585 }
586 
587 
AllocTaxa(void)588 int AllocTaxa (void)
589 {
590     int             i;
591 
592     if (defTaxa == NO)
593         {
594         MrBayesPrint ("%s   Number of taxa not defined\n", spacer);
595         return (ERROR);
596         }
597 
598     if (numTaxa == 0)
599         {
600         MrBayesPrint ("%s   Number of taxa is 0\n", spacer);
601         return (ERROR);
602         }
603 
604     /* allocate space for taxa */
605     if (memAllocs[ALLOC_TAXA] == YES)
606         goto errorExit;
607 
608     taxaNames = NULL;           /* This variable is allocated in AddString */
609     taxaInfo =
610         (TaxaInformation *) SafeMalloc ((size_t) numTaxa *
611                                         sizeof (TaxaInformation));
612 
613     if (!taxaInfo)
614         goto errorExit;
615 
616     tipCalibration =
617         (Calibration *) SafeMalloc ((size_t) numTaxa * sizeof (Calibration));
618 
619     if (!tipCalibration)
620         {
621         free (taxaInfo);
622         taxaInfo = NULL;
623         goto errorExit;
624         }
625 
626     for (i = 0; i < numTaxa; i++)
627         {
628         taxaInfo[i].isDeleted = NO;
629         taxaInfo[i].charCount = 0;
630         }
631 
632     memAllocs[ALLOC_TAXA] = YES;
633 
634     /* taxa sets */
635     if (memAllocs[ALLOC_TAXASETS] == YES)
636         goto errorExit;
637 
638     taxaSetNames = NULL;
639     taxaSet = NULL;
640     numTaxaSets = 0;
641     memAllocs[ALLOC_TAXASETS] = YES;    /* safe to free */
642 
643     /* species partitions; allocate space and set default species partition */
644     if (memAllocs[ALLOC_SPECIESPARTITIONS] == YES)
645         goto errorExit;
646 
647     speciespartitionNames = NULL;
648     speciesNameSets = NULL;
649     speciespartitionId =
650         (int **) SafeMalloc ((size_t) numTaxa * sizeof (int *));
651 
652     for (i = 0; i < numTaxa; i++)
653         {
654         speciespartitionId[i] = (int *) SafeMalloc (sizeof (int));
655         speciespartitionId[i][0] = i + 1;   /* 1-based taxon index, do not ask me why */
656         }
657 
658     numDefinedSpeciespartitions = 0;    /* number of defined species partitions */
659     memAllocs[ALLOC_SPECIESPARTITIONS] = YES;   /* safe to do free */
660 
661     /* constraints */
662     if (memAllocs[ALLOC_CONSTRAINTS] == YES)
663         goto errorExit;
664 
665     constraintNames = NULL;
666     definedConstraintsType = NULL;
667     definedConstraint = NULL;
668     definedConstraintTwo = NULL;
669     definedConstraintPruned = NULL;
670     definedConstraintTwoPruned = NULL;
671     numDefinedConstraints = 0;
672     tempActiveConstraints = NULL;
673     memAllocs[ALLOC_CONSTRAINTS] = YES; /* safe to free */
674 
675     /* translate table */
676     transFrom = NULL;
677     transTo = NULL;
678     numTranslates = 0;
679 
680     /* tempSet */
681     if (memAllocs[ALLOC_TMPSET] == YES)
682         goto errorExit;
683 
684     tempSet = (int *) SafeMalloc ((size_t) numTaxa * sizeof (int));
685     tempSetNeg = (int *) SafeMalloc ((size_t) numTaxa * sizeof (int));
686 
687     if (!tempSet || !tempSetNeg)
688         goto errorExit;
689 
690     memAllocs[ALLOC_TMPSET] = YES;
691 
692     /* make sure previous user trees are freed */
693     if (numUserTrees > 0)
694         {
695         MrBayesPrint ("%s   Previous user trees not freed\n", spacer);
696         goto errorExit;
697         }
698 
699     MrBayesPrint ("%s   Allocated taxon set\n", spacer);
700     return NO_ERROR;
701 
702 errorExit:
703     MrBayesPrint ("%s   Problem allocating taxon set\n", spacer);
704     FreeTaxa();
705     return ERROR;
706 }
707 
708 
ChangeCase(char c)709 char ChangeCase (char c)
710 {
711     int     x;
712 
713     x = tolower(c);
714     return (x);
715 }
716 
717 
CharacterCode(char ch,int * charCode,int chType)718 int CharacterCode (char ch, int *charCode, int chType)
719 {
720     if (chType == DNA || chType == RNA)
721         {
722         if ((*charCode = NucID (ch)) == -1)
723             {
724             MrBayesPrint ("%s   Unrecognized DNA/RNA character '%c'\n", spacer, ch);
725             return (ERROR);
726             }
727         }
728     else if (chType == PROTEIN)
729         {
730         if ((*charCode = ProtID (ch)) == -1)
731             {
732             MrBayesPrint ("%s   Unrecognized Protein character '%c'\n", spacer, ch);
733             return (ERROR);
734             }
735         }
736     else if (chType == RESTRICTION)
737         {
738         if ((*charCode = MBResID (ch)) == -1)
739             {
740             MrBayesPrint ("%s   Unrecognized Restriction character '%c'\n", spacer, ch);
741             return (ERROR);
742             }
743         }
744     else if (chType == STANDARD)
745         {
746         if ((*charCode = StandID (ch)) == -1)
747             {
748             MrBayesPrint ("%s   Unrecognized Standard character '%c'\n", spacer, ch);
749             return (ERROR);
750             }
751         }
752     else if (chType == CONTINUOUS)
753         {
754         MrBayesPrint ("%s   CharacterCode function cannot check continuous characters\n", spacer);
755         }
756     else
757         {
758         MrBayesPrint ("%s   Unrecognized character type (%d)\n", spacer, chType);
759         return (ERROR);
760         }
761 
762     return (NO_ERROR);
763 }
764 
765 
CharacterNumber(int charCode,int chType)766 int CharacterNumber (int charCode, int chType)
767 {
768     int i, x = charCode;
769 
770     if (chType == CONTINUOUS)
771         return 0;
772 
773     for (i=0; x!=0; i++)
774         x >>= 1;
775 
776     return (i);
777 }
778 
779 
CheckInitialPartitions(void)780 int CheckInitialPartitions (void)
781 {
782     int     i;
783 
784     for (i=0; i<numChar; i++)
785         {
786         if (partitionId[i][0] <= 0 || partitionId[i][0] > numDivisions)
787             {
788             MrBayesPrint ("%s   The partition for site %d is incorrect\n", spacer, i+1);
789             return (ERROR);
790             }
791         }
792 
793     return (NO_ERROR);
794 }
795 
796 
CheckStringValidity(char * s)797 int CheckStringValidity (char *s)
798 {
799     int         i, numUnknownChars, tempNumComments, tempInComment;
800     char        temp[100];
801 
802     i = 0;
803     numUnknownChars = 0;
804     tempNumComments = numComments;
805     tempInComment = inComment;
806 
807     while (s[i] != '\0')
808         {
809         if (tempInComment == NO)
810             {
811             if (!IsIn(s[i],"=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789.;:,#()[]?-*/'\\'!%\"&~+^$@|{}`>< "))
812                 {
813                 if (IsWhite(s[i]) == 1 || IsWhite(s[i]) == 2)
814                     {
815 
816                     }
817                 else
818                     {
819                     if (commandPtr == NULL)
820                         return (ERROR);
821                     MrBayesPrint ("%s   Unknown character \"%c\" (ASCII code %d)\n", spacer, s[i], s[i]);
822                     if (!strcmp(commandPtr->string,"Matrix"))
823                         {
824                         if (foundNewLine == NO)
825                             {
826                             MrBayesPrint ("%s   The error is in character %d for taxon %s\n", spacer, taxaInfo[taxonCount-1].charCount+i+1, "???"); /* bug? */
827                             }
828                         else
829                             {
830                             if (taxonCount == 0)
831                                 MrBayesPrint ("%s   The error is in the first taxon name\n", spacer);
832                             else
833                                 {
834                                 strcpy(temp, taxaNames[taxonCount]);
835                                 if (isInterleaved == NO)
836                                     MrBayesPrint ("%s   The error is in the name of the taxon following taxon %s\n", spacer, temp);
837                                 else
838                                     {
839                                     MrBayesPrint ("%s   The error is in the name of the taxon following taxon %s\n", spacer, temp);
840                                     MrBayesPrint ("%s   in one of the interleaved data blocks\n", spacer);
841                                     }
842                                 }
843                             }
844                         }
845                     else if (!strcmp(commandPtr->string,"Execute"))
846                         {
847                         MrBayesPrint ("%s   Assuming irrelevant characters at beginning of file; processing continues\n", spacer);
848                         return (NO_ERROR);
849                         }
850                     return (ERROR);
851                     }
852                 }
853             if (s[i]=='[')
854                 {
855                 tempInComment = YES;
856                 tempNumComments++;
857                 }
858             }
859         else if (tempInComment == YES)
860             {
861             if (s[i]==']')
862                 {
863                 tempNumComments--;
864                 if (tempNumComments == 0)
865                     tempInComment = NO;
866                 }
867             }
868         i++;
869         }
870 
871     if (numUnknownChars > 0)
872         return (ERROR);
873     else
874         return (NO_ERROR);
875 }
876 
877 
878 /* CheckString: This function simply checks a vector of strings for a match against token.
879           Upon return, matchIndex contains the index of the matched string. An
880           ERROR is returned if there are no matches.  */
CheckString(char ** list,int len,char * token,int * matchIndex)881 int CheckString (char **list, int len, char *token, int *matchIndex)
882 {
883     int         i;
884 
885     *matchIndex = -1;
886     for (i=0; i<len; i++)
887         {
888         if (StrCmpCaseInsensitive(token,list[i]) == 0)
889             {
890             *matchIndex = i;
891             return (NO_ERROR);
892             }
893         }
894 
895     return (ERROR);
896 }
897 
898 
Dex(TreeNode * p)899 int Dex (TreeNode *p)
900 {
901     return (p == NULL) ? -1 : p->index;
902 }
903 
904 
DoAbout(void)905 int DoAbout (void)
906 {
907     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
908     MrBayesPrint ("   About the program                                                             \n");
909     MrBayesPrint ("                                                                                 \n");
910     MrBayesPrint ("   MrBayes is a program for the Bayesian estimation of phylogeny. Bayesian       \n");
911     MrBayesPrint ("   inference of phylogeny is based upon the posterior probability distribution   \n");
912     MrBayesPrint ("   of trees. Trees are labelled T1, T2, ..., Tn, where n is the number of        \n");
913     MrBayesPrint ("   possible trees. The posterior probability of the i-th tree is calculated      \n");
914     MrBayesPrint ("   using Bayes\'s formula as                                                     \n");
915     MrBayesPrint ("                                                                                 \n");
916     MrBayesPrint ("      Pr[Ti | X] = Pr[X | Ti] X Pr[Ti] / Pr[X]                                   \n");
917     MrBayesPrint ("                                                                                 \n");
918     MrBayesPrint ("   where X is a character matrix. Here, \"Pr[Ti | X]\" is the posterior          \n");
919     MrBayesPrint ("   probability of the i-th tree, \"Pr[X | Ti]\" is the likelihood of the         \n");
920     MrBayesPrint ("   i-th tree, and \"Pr[Ti]\" is the prior probability of the i-th tree. The      \n");
921     MrBayesPrint ("   denominator of Bayes\'s formula (\"Pr[X]\") is a normalizing constant that    \n");
922     MrBayesPrint ("   involves a summation over all possible trees. The likelihood, as described    \n");
923     MrBayesPrint ("   above, cannot be calculated with knowledge of only the tree\'s topology. You  \n");
924     MrBayesPrint ("   also need to have information on the lenths of the branches and on the        \n");
925     MrBayesPrint ("   mechanism of character change. Hence, the likelihood (\"Pr[X | Ti]\")         \n");
926     MrBayesPrint ("   involves a multidimensional integral over all possible combinations of        \n");
927     MrBayesPrint ("   branch lengths and substitution model parameters.                             \n");
928     MrBayesPrint ("                                                                                 \n");
929     MrBayesPrint ("   In practice, it is impossible to calculate the posterior probability dist-    \n");
930     MrBayesPrint ("   ribution of trees analytically. Instead, the posterior probability            \n");
931     MrBayesPrint ("   of trees must be approximated. MrBayes uses a method called Markov chain      \n");
932     MrBayesPrint ("   Monte Carlo (MCMC) to approximate the posterior probability of trees.         \n");
933     MrBayesPrint ("   The object of MCMC is to construct a Markov chain that has as its state       \n");
934     MrBayesPrint ("   space the parameters of the phylogenetic model and a stationary distribution  \n");
935     MrBayesPrint ("   that is the posterior probability distribution of trees. MCMC takes valid,    \n");
936     MrBayesPrint ("   albeit dependent, samples from the posterior probability distribution of      \n");
937     MrBayesPrint ("   trees. The fraction of the time any tree appears in this sample is a          \n");
938     MrBayesPrint ("   valid approximation of the posterior probability of the tree. MrBayes keeps   \n");
939     MrBayesPrint ("   track of all the parameters of the phylogenetic model. The trees (with branch \n");
940     MrBayesPrint ("   lengths) that were sampled by the MCMC procedure are saved in one file        \n");
941     MrBayesPrint ("   (a file with a \".t\" extension) whereas the parameters of the model of       \n");
942     MrBayesPrint ("   character change are saved in another file (a file with a \".p\" ext-         \n");
943     MrBayesPrint ("   ension). You can summarize the results in the \".t\" and \".p\" files         \n");
944     MrBayesPrint ("   using the \"sumt\" and \"sump\" commands, respectively.                       \n");
945     MrBayesPrint ("                                                                                 \n");
946     MrBayesPrint ("   MrBayes was originally written by John Huelsenbeck in August of 2000 and was  \n");
947     MrBayesPrint ("   intended to be distributed to a small number of people. In March of 2001,     \n");
948     MrBayesPrint ("   Fredrik Ronquist started making contributions to the program. The contribu-   \n");
949     MrBayesPrint ("   tions were of such a significant nature that he was made a coauthor of the    \n");
950     MrBayesPrint ("   program. Version 3 of MrBayes was a fully joint effort, started in the summer \n");
951     MrBayesPrint ("   of 2002 when JPH visited Sweden on a grant from the Wenner-Gren Foundations.  \n");
952     MrBayesPrint ("   Several others have contributed to the MrBayes code since then, most notably  \n");
953     MrBayesPrint ("   Paul van der Mark, Maxim Teslenko and Chi Zhang, all postdocs/programmers in  \n");
954     MrBayesPrint ("   Fredrik's lab. A large number of users and students, too many to list here,   \n");
955     MrBayesPrint ("   have also contributed importantly to the project (type 'Acknowledgments' for  \n");
956     MrBayesPrint ("   a list of some of them).                                                      \n");
957     MrBayesPrint ("                                                                                 \n");
958     MrBayesPrint ("   From 2003, MrBayes was distributed from SourceForge; the repository was moved \n");
959     MrBayesPrint ("   to GitHub in 2018, when the project entered maintenance phase and the res-    \n");
960     MrBayesPrint ("   ponsibility was transferred to National Bioinformatics Infrastructure Sweden  \n");
961     MrBayesPrint ("   (https://nbis.se), where Andreas Kahari and Johan Nylander jointly take care  \n");
962     MrBayesPrint ("   of bug fixes, documentation updates, and other maintenance tasks.             \n");
963     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
964 
965     return (NO_ERROR);
966 }
967 
968 
DoAcknowledgments(void)969 int DoAcknowledgments (void)
970 {
971     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
972     MrBayesPrint ("   Acknowledgments                                                               \n");
973     MrBayesPrint ("                                                                                 \n");
974     MrBayesPrint ("   JPH and FR would like to thank Gautam Altekar, Andrea Betancourt, Jon         \n");
975     MrBayesPrint ("   Bollback, Barry Hall, Jimmy McGuire, Rasmus Nielsen, David Swofford,          \n");
976     MrBayesPrint ("   Johan Nylander, Mikael Thollesson, and Derrick Zwickl for help during the     \n");
977     MrBayesPrint ("   initial development of this program. Gautam Altekar, especially, was instru-  \n");
978     MrBayesPrint ("   mental in getting the parallel version of the program working. Important bug- \n");
979     MrBayesPrint ("   fixes and additional functionality was contributed by Clemens Lakner, Sebas-  \n");
980     MrBayesPrint ("   tian Hoehna, Paul Lewis, Mark Holder, Julian Catchen and Bret Larget. Marc    \n");
981     MrBayesPrint ("   Suchard, Daniel Ayres and Aaron Darling got mrbayes working with beagle and   \n");
982     MrBayesPrint ("   contributed a lot of related functionality and bug fixes. Aaron Darling was   \n");
983     MrBayesPrint ("   instrumental in getting the Windows installer set up. Liu Liang and Dennis    \n");
984     MrBayesPrint ("   Pearl helped integrate MrBayes with BEST.                                     \n");
985     MrBayesPrint ("                                                                                 \n");
986     MrBayesPrint ("   Bug fixes and user support was provided by Paul van der Mark (2005-2007),     \n");
987     MrBayesPrint ("   Maxim Teslenko (2010-2012) and Chi Zhang (2012-2015). From 2015, Andreas      \n");
988     MrBayesPrint ("   Kahari and Johan Nylander at the National Bioinformatics Infrastructure       \n");
989     MrBayesPrint ("   Sweden (NBIS; https://nbis.se) have been responsible for bug fixes and        \n");
990     MrBayesPrint ("   maintenance of the code base.                                                 \n");
991     MrBayesPrint ("                                                                                 \n");
992     MrBayesPrint ("   Our wives -- Edna Huelsenbeck and Eva Ronquist -- showed extraordinary        \n");
993     MrBayesPrint ("   patience with us while we spent many late nights programming.                 \n");
994     MrBayesPrint ("                                                                                 \n");
995     MrBayesPrint ("   JPH was supported by NSF grants DEB-007540 and MCB-0075404 and a Wenner-      \n");
996     MrBayesPrint ("   Gren scholarship while writing this program. FR was supported by grants       \n");
997     MrBayesPrint ("   from the Swedish Natural Science Research Council and the Swedish Research    \n");
998     MrBayesPrint ("   Council, which also supports NBIS work on MrBayes.                            \n");
999     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
1000 
1001     return (NO_ERROR);
1002 }
1003 
1004 
DoBeginParm(char * parmName,char * tkn)1005 int DoBeginParm (char *parmName, char *tkn)
1006 {
1007     if (expecting == Expecting(PARAMETER))
1008         {
1009         /* set Data (inDataBlock) *************************************************************/
1010         if (!strcmp(parmName, "Data"))
1011             {
1012             if (FreeModel () == ERROR)
1013                 return (ERROR);
1014             if (FreeMatrix () == ERROR)
1015                 return (ERROR);
1016             MrBayesPrint ("   Reading data block\n");
1017             inDataBlock = YES;
1018             expecting = Expecting(SEMICOLON);
1019             strcpy (spacer, "   ");
1020             }
1021         /* set Characters (inCharactersBlock) *************************************************************/
1022         else if (!strcmp(parmName, "Characters"))
1023             {
1024             if (FreeModel () == ERROR)
1025                 return (ERROR);
1026             if (FreeCharacters () == ERROR)
1027                 return (ERROR);
1028             MrBayesPrint ("   Reading characters block\n");
1029             inCharactersBlock = YES;
1030             expecting = Expecting(SEMICOLON);
1031             strcpy (spacer, "   ");
1032             }
1033         /* set Taxa (inTaxaBlock) *************************************************************/
1034         else if (!strcmp(parmName, "Taxa"))
1035             {
1036             if (FreeModel () == ERROR)
1037                 return (ERROR);
1038             if (FreeMatrix () == ERROR)
1039                 return (ERROR);
1040             MrBayesPrint ("   Reading taxa block\n");
1041             inTaxaBlock = YES;
1042             expecting = Expecting(SEMICOLON);
1043             strcpy (spacer, "   ");
1044             }
1045         /* set Mrbayes (inMrbayesBlock) *******************************************************/
1046         else if (!strcmp(parmName, "Mrbayes"))
1047             {
1048             MrBayesPrint ("   Reading mrbayes block\n");
1049             inMrbayesBlock = YES;
1050             expecting = Expecting(SEMICOLON);
1051             strcpy (spacer, "   ");
1052             }
1053         /* set Trees (inTreesBlock) *******************************************************/
1054         else if (!strcmp(parmName, "Trees"))
1055             {
1056             MrBayesPrint ("   Reading trees block\n");
1057             inTreesBlock = YES;
1058             expecting = Expecting(SEMICOLON);
1059             strcpy (spacer, "   ");
1060             }
1061         /* set Foreign (inForeignBlock) *******************************************************/
1062         else
1063             {
1064             MrBayesPrint ("   Skipping \"%s\" block\n", tkn);
1065             inForeignBlock = YES;
1066             expecting = Expecting(SEMICOLON);
1067             strcpy (spacer, "");
1068             }
1069         }
1070     else
1071         return (ERROR);
1072 
1073     return (NO_ERROR);
1074 }
1075 
1076 
DoBreaks(void)1077 int DoBreaks (void)
1078 {
1079     int         i, numBreaks;
1080 
1081     numBreaks = 0;
1082     for (i=0; i<numChar; i++)
1083         {
1084         if (charInfo[i].bigBreakAfter == YES)
1085             {
1086             numBreaks++;
1087             }
1088         }
1089 
1090     if (numBreaks > 0)
1091         {
1092         if (numBreaks == 1)
1093             MrBayesPrint ("%s   One data break found after character ", spacer, numBreaks);
1094         else
1095             MrBayesPrint ("%s   %d data breaks found after characters: ", spacer, numBreaks);
1096         for (i=0; i<numChar; i++)
1097             {
1098             if (charInfo[i].bigBreakAfter == YES)
1099                 {
1100                 MrBayesPrint ("%d ", i+1);
1101                 }
1102             }
1103         MrBayesPrint ("\n");
1104 
1105         if (numBreaks == 1)
1106             MrBayesPrint ("%s   Successfully defined one break in data\n", spacer);
1107         else
1108             MrBayesPrint ("%s   Successfully defined %d breaks in data\n", spacer, numBreaks);
1109         }
1110     else
1111         {
1112         MrBayesPrint ("%s   No breaks in data found\n", spacer);
1113         }
1114 
1115     return (NO_ERROR);
1116 }
1117 
1118 
DoBreaksParm(char * parmName,char * tkn)1119 int DoBreaksParm (char *parmName, char *tkn)
1120 {
1121     int     i, tempInt;
1122 
1123     if (defMatrix == NO)
1124         {
1125         MrBayesPrint ("%s   A matrix must be specified before you can define breaks in the data\n", spacer);
1126         return (ERROR);
1127         }
1128 
1129     if (expecting == Expecting(NUMBER))
1130         {
1131         sscanf (tkn, "%d", &tempInt);
1132         if (tempInt <= 0 || tempInt > numChar)
1133             {
1134             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
1135             for (i=0; i<numChar; i++)
1136                 charInfo[i].bigBreakAfter = NO;
1137             return (ERROR);
1138             }
1139         if (tempInt == numChar)
1140             {
1141             MrBayesPrint ("%s   Character number %d is the last character. MrBayes will define the\n", spacer, tempInt);
1142             MrBayesPrint ("%s   break, even though it doesn't make too much sense.\n", spacer);
1143             }
1144         tempInt--;
1145 
1146         charInfo[tempInt].bigBreakAfter = YES;
1147 
1148         expecting  = (Expecting(NUMBER) | Expecting(SEMICOLON));
1149         }
1150     else
1151         {
1152         for (i=0; i<numChar; i++)
1153             charInfo[i].bigBreakAfter = NO;
1154         return (ERROR);
1155         }
1156 
1157     return (NO_ERROR);
1158 }
1159 
1160 
DoCalibrate(void)1161 int DoCalibrate (void)
1162 {
1163     int         i;
1164 
1165     /* show calibration times (for debugging) */
1166 #   if 0
1167     MrBayesPrint ("Taxon ages\n");
1168     for (i=0; i<numTaxa; i++)
1169         MrBayesPrint ("%4d  --  %s\n", i+1, tipCalibration[i].name);
1170     MrBayesPrint ("Constraint ages\n");
1171     for (i=0; i<numDefinedConstraints; i++)
1172         {
1173         if (definedConstraintsType[i] != HARD)
1174             continue;
1175         MrBayesPrint ("%4d  --  %s\n", i+1, nodeCalibration[i].name);
1176         }
1177 #   endif
1178 
1179     /* Update model if calibrations enforced */
1180     for (i=0; i<numCurrentDivisions; i++)
1181         {
1182         if (!strcmp(modelParams[i].nodeAgePr,"Calibrated"))
1183             {
1184             if (SetUpAnalysis (&globalSeed) == ERROR)
1185                 return (ERROR);
1186             break;
1187             }
1188         }
1189 
1190     return (NO_ERROR);
1191 }
1192 
1193 
DoCalibrateParm(char * parmName,char * tkn)1194 int DoCalibrateParm (char *parmName, char *tkn)
1195 {
1196     static int              isTaxon, paramIndex;
1197     static char             nodeName[100], calName[100];
1198     static MrBFlt           priorParams[3];
1199     static enum CALPRIOR    calPrior;
1200     int                     howMany, index;
1201     char                    s[20], tempStr[100];
1202     MrBFlt                  tempD;
1203 
1204     if (defMatrix == NO)
1205         {
1206         MrBayesPrint ("%s   A matrix must be specified before you can calibrate nodes\n", spacer);
1207         return (ERROR);
1208         }
1209 
1210     if (expecting == Expecting(PARAMETER))
1211         {
1212         if (strcmp(parmName, "Xxxxxxxxxx") != 0)
1213             {
1214             MrBayesPrint ("%s   Unexpected error - Wrong parmName in DoCalibrateParm\n", spacer);
1215             return (ERROR);
1216             }
1217 
1218         /* find taxon with this name */
1219         calibrationPtr = NULL;
1220         howMany = 0;
1221 
1222         /* first look in constraint names */
1223         if (CheckString (constraintNames, numDefinedConstraints, tkn, &index) != ERROR && definedConstraintsType[index] == HARD)
1224             {
1225             calibrationPtr = &nodeCalibration[index];
1226             howMany++;
1227             isTaxon = NO;
1228             strcpy (nodeName, tkn);
1229             }
1230 
1231         /* then look in terminal taxon names */
1232         if (CheckString (taxaNames, numTaxa, tkn, &index) != ERROR)
1233             {
1234             calibrationPtr = &tipCalibration[index];
1235             howMany++;
1236             isTaxon = YES;
1237             strcpy (nodeName, tkn);
1238             }
1239 
1240         /* return error if not found or ambiguous */
1241         if (howMany == 0)
1242             {
1243             MrBayesPrint ("%s   No taxon or hard constraint named ""%s"" found. Note that only hard constraint can be calibrated.\n", spacer, tkn);
1244             return (ERROR);
1245             }
1246         else if (howMany > 1)
1247             {
1248             MrBayesPrint ("%s   Both a taxon and a constraint named ""%s"" encountered -- please rename one\n", spacer, tkn);
1249             return (ERROR);
1250             }
1251 
1252         /* get ready to find the equal sign */
1253         expecting = Expecting(EQUALSIGN);
1254         }
1255 
1256     else if (expecting == Expecting(EQUALSIGN))
1257         {
1258         /* get ready to find the calibration prior */
1259         expecting = Expecting(ALPHA);
1260         }
1261 
1262     else if (expecting == Expecting(ALPHA))
1263         {
1264         /* set the calibration prior type */
1265         if (IsArgValid(tkn,tempStr) == NO_ERROR)
1266             {
1267             if (!strcmp (tempStr, "Unconstrained"))
1268                 calPrior = unconstrained;
1269             else if (!strcmp (tempStr, "Fixed"))
1270                 calPrior = fixed;
1271             else if (!strcmp (tempStr, "Uniform"))
1272                 calPrior = uniform;
1273             else if (!strcmp (tempStr, "Offsetexponential"))
1274                 calPrior = offsetExponential;
1275             else if (!strcmp (tempStr, "Truncatednormal"))
1276                 calPrior = truncatedNormal;
1277             else if (!strcmp (tempStr, "Lognormal"))
1278                 calPrior = logNormal;
1279             else if (!strcmp (tempStr, "Offsetlognormal"))
1280                 calPrior = offsetLogNormal;
1281             else if (!strcmp (tempStr, "Gamma"))
1282                 calPrior = standardGamma;
1283             else if (!strcmp (tempStr, "Offsetgamma"))
1284                 calPrior = offsetGamma;
1285 
1286             if (calPrior == unconstrained)
1287                 {
1288                 /* reset the values of the calibration */
1289                 MrBayesPrint ("%s   Resetting previous calibration for ""%s""\n", spacer, nodeName);
1290 
1291                 calibrationPtr->prior           = defaultCalibration.prior;
1292                 calibrationPtr->priorParams[0]  = defaultCalibration.priorParams[0];
1293                 calibrationPtr->priorParams[1]  = defaultCalibration.priorParams[1];
1294                 calibrationPtr->priorParams[2]  = defaultCalibration.priorParams[2];
1295                 calibrationPtr->LnPriorProb     = defaultCalibration.LnPriorProb;
1296                 calibrationPtr->LnPriorRatio    = defaultCalibration.LnPriorRatio;
1297                 calibrationPtr->min             = defaultCalibration.min;
1298                 calibrationPtr->max             = defaultCalibration.max;
1299                 strcpy(calibrationPtr->name, defaultCalibration.name);
1300 
1301                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
1302                 }
1303             else
1304                 {
1305                 strcpy (calName, tempStr);
1306                 paramIndex = 0;
1307                 priorParams[0] = priorParams[1] = priorParams[2] =  -1.0;
1308                 expecting = Expecting(LEFTPAR);
1309                 }
1310             }
1311         else
1312             {
1313             MrBayesPrint ("%s   Invalid calibration prior argument \n", spacer);
1314             return (ERROR);
1315             }
1316         }
1317     else if (expecting == Expecting(LEFTPAR))
1318         {
1319         strcat (calName, "(");
1320         expecting  = Expecting(NUMBER);
1321         }
1322     else if (expecting == Expecting(NUMBER))
1323         {
1324         sscanf (tkn, "%lf", &tempD);
1325         if (paramIndex == 0)
1326             {
1327             if (calPrior == logNormal)
1328                 {
1329                 if (tempD < 0.0)
1330                     {
1331                     MrBayesPrint ("%s   Mean age must be nonnegative\n", spacer);
1332                     MrBayesPrint ("%s   Parameters of the lognormal distribution used for dating are mean age\n", spacer);
1333                     MrBayesPrint ("%s   and standard deviation, both specified on the linear scale, not as log values.\n", spacer);
1334                     return (ERROR);
1335                     }
1336                 }
1337             else if (calPrior == standardGamma)
1338                 {
1339                 if (tempD <= 0.0)
1340                     {
1341                     MrBayesPrint ("%s   Mean parameter must be positive\n", spacer);
1342                     MrBayesPrint ("%s   Parameters of the gamma distribution used for dating are mean age and\n", spacer);
1343                     MrBayesPrint ("%s   standard deviation. In terms of the common shape (alpha) and rate (beta)\n", spacer);
1344                     MrBayesPrint ("%s   parameterization, the expected mean is alpha/beta and the standard\n", spacer);
1345                     MrBayesPrint ("%s   deviation is the square root of (alpha / beta^2).\n", spacer);
1346                     return (ERROR);
1347                     }
1348                 }
1349             else if (tempD < 0.0)
1350                 {
1351                 if (calPrior == fixed)
1352                     MrBayesPrint ("%s   Fixed age must be nonnegative\n", spacer);
1353                 else if (calPrior == uniform)
1354                     {
1355                     MrBayesPrint ("%s   Minimum age must be nonnegative\n", spacer);
1356                     MrBayesPrint ("%s   Parameters of the uniform are minimum age and maximum age.\n", spacer);
1357                     }
1358                 else if (calPrior == truncatedNormal)
1359                     {
1360                     MrBayesPrint ("%s   Offset (minimum or truncation) age must be nonnegative.\n", spacer);
1361                     MrBayesPrint ("%s   Parameters of the truncated normal distribution are offset (minimum\n", spacer);
1362                     MrBayesPrint ("%s   or truncation) age, mean age and standard deviation.\n", spacer);
1363                     }
1364                 else if (calPrior == offsetGamma)
1365                     {
1366                     MrBayesPrint ("%s   Offset age must be nonnegative\n", spacer);
1367                     MrBayesPrint ("%s   Parameters of the offset gamma distribution used for dating are offset age,\n", spacer);
1368                     MrBayesPrint ("%s   mean age, and standard deviation. In terms of the common shape (alpha) and\n", spacer);
1369                     MrBayesPrint ("%s   rate (beta) parameterization, the expected mean is alpha/beta and the standard\n", spacer);
1370                     MrBayesPrint ("%s   deviation is the square root of (alpha / beta^2).\n", spacer);
1371                     }
1372                 else if (calPrior == offsetExponential)
1373                     {
1374                     MrBayesPrint ("%s   Offset age must be nonnegative\n", spacer);
1375                     MrBayesPrint ("%s   Parameters of the offset exponential are offset age and mean age.\n", spacer);
1376                     }
1377                 else if (calPrior == offsetLogNormal)
1378                     {
1379                     MrBayesPrint ("%s   Offset age must be nonnegative\n", spacer);
1380                     MrBayesPrint ("%s   Parameters of the offset lognormal distribution are offset age, mean age,\n", spacer);
1381                     MrBayesPrint ("%s   and standard deviation. All values are specified on the linear scale, not\n", spacer);
1382                     MrBayesPrint ("%s   as log values.\n", spacer);
1383                     }
1384                 return (ERROR);
1385                 }
1386             priorParams[0] = tempD;
1387             if (calPrior == fixed)
1388                 expecting = Expecting(RIGHTPAR);
1389             else
1390                 expecting = Expecting(COMMA);
1391             }
1392         else if (paramIndex == 1)
1393             {
1394             if (calPrior == uniform)
1395                 {
1396                 if (tempD <= priorParams[0])
1397                     {
1398                     MrBayesPrint ("%s   Maximum age of uniform distribution must be larger than minimum age\n", spacer);
1399                     return (ERROR);
1400                     }
1401                 }
1402             else if (calPrior == offsetExponential)
1403                 {
1404                 if (tempD <= priorParams[0])
1405                     {
1406                     MrBayesPrint ("%s   Mean age must be larger than offset age.\n", spacer);
1407                     MrBayesPrint ("%s   MrBayes now uses offset and mean rather than offset and rate\n", spacer);
1408                     MrBayesPrint ("%s   as the parameters for the offset exponential distribution.\n", spacer);
1409                     return (ERROR);
1410                     }
1411                 }
1412             else if (calPrior == truncatedNormal)
1413                 {
1414                 if (tempD <= priorParams[0])
1415                     {
1416                     MrBayesPrint ("%s   Mean age must be larger than offset (truncation) age.\n", spacer);
1417                     MrBayesPrint ("%s   Parameters of the truncated normal distribution are offset (minimum\n", spacer);
1418                     MrBayesPrint ("%s   or truncation) age, mean age and standard deviation\n", spacer);
1419                     return (ERROR);
1420                     }
1421                 }
1422             else if (calPrior == logNormal)
1423                 {
1424                 if (tempD <= 0.0)
1425                     {
1426                     MrBayesPrint ("%s   Standard deviation must be positive.\n", spacer);
1427                     MrBayesPrint ("%s   Parameters of the lognormal distribution used for dating are mean age\n", spacer);
1428                     MrBayesPrint ("%s   and standard deviation, both specified on the linear scale, not as log values.\n", spacer);
1429                     return (ERROR);
1430                     }
1431                 }
1432             else if (calPrior == offsetLogNormal)
1433                 {
1434                 if (tempD <= priorParams[0])
1435                     {
1436                     MrBayesPrint ("%s   Mean age must be larger than offset age.\n", spacer);
1437                     MrBayesPrint ("%s   Parameters of the offset lognormal distribution are offset age, mean age,\n", spacer);
1438                     MrBayesPrint ("%s   and standard deviation. All values are specified on the linear scale, not\n", spacer);
1439                     MrBayesPrint ("%s   as log values.\n", spacer);
1440                     return (ERROR);
1441                     }
1442                 }
1443             else if (calPrior == standardGamma)
1444                 {
1445                 if (tempD <= 0.0)
1446                     {
1447                     MrBayesPrint ("%s   Standard deviation must be positive.\n", spacer);
1448                     MrBayesPrint ("%s   Parameters of the gamma distribution used for dating are mean age and\n", spacer);
1449                     MrBayesPrint ("%s   standard deviation. In terms of the common shape (alpha) and rate (beta)\n", spacer);
1450                     MrBayesPrint ("%s   parameterization, the expected mean is alpha/beta and the standard\n", spacer);
1451                     MrBayesPrint ("%s   deviation is the square root of (alpha / beta^2).\n", spacer);
1452                     return (ERROR);
1453                     }
1454                 }
1455             else if (calPrior == offsetGamma)
1456                 {
1457                 if (tempD <= 0.0)
1458                     {
1459                     MrBayesPrint ("%s   Mean age must be positive.\n", spacer);
1460                     MrBayesPrint ("%s   Parameters of the offset gamma distribution used for dating are offset age,\n", spacer);
1461                     MrBayesPrint ("%s   mean age, and standard deviation. In terms of the common shape (alpha) and\n", spacer);
1462                     MrBayesPrint ("%s   rate (beta) parameterization, the expected mean is alpha/beta and the standard\n", spacer);
1463                     MrBayesPrint ("%s   deviation is the square root of (alpha / beta^2).\n", spacer);
1464                     return (ERROR);
1465                     }
1466                 }
1467 
1468             priorParams[1] = tempD;
1469             if (calPrior == uniform || calPrior == standardGamma || calPrior == logNormal || calPrior == offsetExponential)
1470                 expecting = Expecting(RIGHTPAR);
1471             else
1472                 expecting = Expecting(COMMA);
1473             }
1474         else /* if (paramIndex == 2) */
1475             {
1476             if (calPrior == offsetGamma)
1477                 {
1478                 if (tempD <= 0.0)
1479                     {
1480                     MrBayesPrint ("%s   Standard deviation must be positive.\n", spacer);
1481                     MrBayesPrint ("%s   Parameters of the offset gamma distribution used for dating are offset age,\n", spacer);
1482                     MrBayesPrint ("%s   mean age, and standard deviation. In terms of the common shape (alpha) and\n", spacer);
1483                     MrBayesPrint ("%s   rate (beta) parameterization, the expected mean is alpha/beta and the standard\n", spacer);
1484                     MrBayesPrint ("%s   deviation is the square root of (alpha / beta^2).\n", spacer);
1485                     return (ERROR);
1486                     }
1487                 }
1488             else if (calPrior == offsetLogNormal)
1489                 {
1490                 if (tempD <= 0.0)
1491                     {
1492                     MrBayesPrint ("%s   Standard deviation must be positive.\n", spacer);
1493                     MrBayesPrint ("%s   Parameters of the offset lognormal distribution are offset age, mean age,\n", spacer);
1494                     MrBayesPrint ("%s   and standard deviation. All values are specified on the linear scale, not\n", spacer);
1495                     MrBayesPrint ("%s   as log values.\n", spacer);
1496                     return (ERROR);
1497                     }
1498                 }
1499             priorParams[2] = tempD;
1500             expecting = Expecting(RIGHTPAR);
1501             }
1502         sprintf (s, "%1.2lf", tempD);
1503         strcat (calName, s);
1504         }
1505     else if (expecting == Expecting(COMMA))
1506         {
1507         strcat (calName, ",");
1508         paramIndex++;
1509         expecting  = Expecting(NUMBER);
1510         }
1511     else if (expecting == Expecting(RIGHTPAR))
1512         {
1513         strcat (calName, ")");
1514         if (isTaxon == YES)
1515             MrBayesPrint ("%s   Setting age of taxon '%s' to %s\n", spacer, nodeName, calName);
1516         else
1517             MrBayesPrint ("%s   Setting age of constraint node '%s' to %s\n", spacer, nodeName, calName);
1518 
1519         /* set calibration based on collected values and settings */
1520         strcpy(calibrationPtr->name, calName);
1521         calibrationPtr->priorParams[0]  = priorParams[0];
1522         calibrationPtr->priorParams[1]  = priorParams[1];
1523         calibrationPtr->priorParams[2]  = priorParams[2];
1524         calibrationPtr->prior           = calPrior;
1525         if (calPrior == fixed)
1526             {
1527             calibrationPtr->LnPriorProb     = &LnPriorProbFix;
1528             calibrationPtr->LnPriorRatio    = &LnProbRatioFix;
1529             calibrationPtr->min             = priorParams[0];
1530             calibrationPtr->max             = priorParams[0];
1531             }
1532         else if (calPrior == uniform)
1533             {
1534             calibrationPtr->LnPriorProb     = &LnPriorProbUniform;
1535             calibrationPtr->LnPriorRatio    = &LnProbRatioUniform;
1536             calibrationPtr->min             = priorParams[0];
1537             calibrationPtr->max             = priorParams[1];
1538             }
1539         else if (calPrior == offsetExponential)
1540             {
1541             calibrationPtr->LnPriorProb     = &LnPriorProbOffsetExponential_Param_Offset_Mean;
1542             calibrationPtr->LnPriorRatio    = &LnProbRatioOffsetExponential_Param_Offset_Mean;
1543             calibrationPtr->min             = priorParams[0];
1544             calibrationPtr->max             = POS_INFINITY;
1545             }
1546         else if (calPrior == truncatedNormal)
1547             {
1548             calibrationPtr->LnPriorProb     = &LnPriorProbTruncatedNormal_Param_Trunc_Mean_Sd;
1549             calibrationPtr->LnPriorRatio    = &LnProbRatioTruncatedNormal_Param_Trunc_Mean_Sd;
1550             calibrationPtr->min             = priorParams[0];
1551             calibrationPtr->max             = POS_INFINITY;
1552             }
1553         else if (calPrior == logNormal)
1554             {
1555             calibrationPtr->LnPriorProb     = &LnPriorProbLognormal_Param_Mean_Sd;
1556             calibrationPtr->LnPriorRatio    = &LnProbRatioLognormal_Param_Mean_Sd;
1557             calibrationPtr->min             = BRLENS_MIN;
1558             calibrationPtr->max             = POS_INFINITY;
1559             }
1560         else if (calPrior == offsetLogNormal)
1561             {
1562             calibrationPtr->LnPriorProb     = &LnPriorProbOffsetLognormal_Param_Offset_Mean_Sd;
1563             calibrationPtr->LnPriorRatio    = &LnProbRatioOffsetLognormal_Param_Offset_Mean_Sd;
1564             calibrationPtr->min             = BRLENS_MIN + priorParams[0];
1565             calibrationPtr->max             = POS_INFINITY;
1566             }
1567         else if (calPrior == standardGamma)
1568             {
1569             calibrationPtr->LnPriorProb     = &LnPriorProbGamma_Param_Mean_Sd;
1570             calibrationPtr->LnPriorRatio    = &LnProbRatioGamma_Param_Mean_Sd;
1571             calibrationPtr->min             = BRLENS_MIN;
1572             calibrationPtr->max             = POS_INFINITY;
1573             }
1574         else if (calPrior == offsetGamma)
1575             {
1576             calibrationPtr->LnPriorProb     = &LnPriorProbOffsetGamma_Param_Offset_Mean_Sd;
1577             calibrationPtr->LnPriorRatio    = &LnProbRatioOffsetGamma_Param_Offset_Mean_Sd;
1578             calibrationPtr->min             = BRLENS_MIN + priorParams[0];
1579             calibrationPtr->max             = POS_INFINITY;
1580             }
1581 
1582         /* get ready to find more calibrated nodes or taxa, if present */
1583         expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
1584         }
1585     else
1586         return (ERROR);
1587 
1588     return (NO_ERROR);
1589 }
1590 
1591 
DoCharset(void)1592 int DoCharset (void)
1593 {
1594     /* first add set to tempSet */
1595     if (fromI >= 0 && toJ < 0)
1596         {
1597         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1598             return (ERROR);
1599         }
1600     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
1601         {
1602         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1603             return (ERROR);
1604         }
1605     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
1606         {
1607         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1608             return (ERROR);
1609         }
1610 
1611     /* add name to charSetNames */
1612     if (AddString (&charSetNames, numCharSets, tempSetName) == ERROR)
1613         {
1614         MrBayesPrint ("%s   Problem adding charset %s to list\n", spacer, tempSetName);
1615         return (ERROR);
1616         }
1617 
1618     /* store charset */
1619     AddBitfield (&charSet, numCharSets, tempSet, numChar);
1620 
1621     /* increment number of char sets */
1622     numCharSets++;
1623 
1624     return (NO_ERROR);
1625 }
1626 
1627 
DoCharsetParm(char * parmName,char * tkn)1628 int DoCharsetParm (char *parmName, char *tkn)
1629 {
1630     int     i, index, tempInt, allDigit;
1631 
1632     if (defMatrix == NO)
1633         {
1634         MrBayesPrint ("%s   A matrix must be specified before charsets can be defined\n", spacer);
1635         return (ERROR);
1636         }
1637 
1638     if (expecting == Expecting(PARAMETER))
1639         {
1640         if (!strcmp(parmName, "Xxxxxxxxxx"))
1641             {
1642             /* check that the name of the charset is not a number */
1643             allDigit = YES;
1644             for (i=0; i<(int)strlen(tkn); i++)
1645                 {
1646                 if (tkn[i] == '0' || tkn[i] == '1' || tkn[i] == '2' || tkn[i] == '3' || tkn[i] == '4' ||
1647                     tkn[i] == '5' || tkn[i] == '6' || tkn[i] == '7' || tkn[i] == '8' || tkn[i] == '9' || tkn[i] == '.')
1648                     {}
1649                 else
1650                     allDigit = NO;
1651                 }
1652             if (allDigit == YES)
1653                 {
1654                 MrBayesPrint ("%s   Charset name may not be a number\n", spacer);
1655                 return (ERROR);
1656                 }
1657 
1658             /* check size of charset name */
1659             if (strlen(tkn) > 99)
1660                 {
1661                 MrBayesPrint ("%s   Charset name is too long\n", spacer);
1662                 return (ERROR);
1663                 }
1664 
1665             /* check to see if the name has already been used as a charset */
1666             if (numCharSets > 1)
1667                 {
1668                 if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
1669                     {
1670                     /* if the charset name has not been used, then we should have an ERROR returned */
1671                     /* we _want_ to be here */
1672 
1673                     }
1674                 else
1675                     {
1676                     MrBayesPrint ("%s   Charset name has been used previously\n", spacer);
1677                     return (ERROR);
1678                     }
1679                 }
1680 
1681             /* add the name to the character set */
1682             strcpy (tempSetName, tkn);
1683 
1684             /* clear tempSet */
1685             for (i=0; i<numChar; i++)
1686                 tempSet[i] = 0;
1687 
1688             fromI = toJ = everyK = -1;
1689             foundDash = foundSlash = NO;
1690             MrBayesPrint ("%s   Defining charset called '%s'\n", spacer, tkn);
1691             expecting = Expecting(EQUALSIGN);
1692             }
1693         else
1694             return (ERROR);
1695         }
1696     else if (expecting == Expecting(EQUALSIGN))
1697         {
1698         expecting  = Expecting(ALPHA);
1699         expecting |= Expecting(NUMBER);
1700         }
1701     else if (expecting == Expecting(ALPHA))
1702         {
1703         /* We are defining a character set in terms of another (called tkn, here). We should be able
1704            to find tkn in the list of character set names. If we cannot, then we have a problem and
1705            return an error. */
1706         if (numCharSets < 1)
1707             {
1708             MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
1709             return (ERROR);
1710             }
1711         if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
1712             {
1713             MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
1714             return (ERROR);
1715             }
1716         /* add characters from charset "tkn" to new tempset */
1717         for (i=0; i<numChar; i++)
1718             {
1719             if (IsBitSet(i,charSet[index]) == YES)
1720                 tempSet[i] = 1;
1721             }
1722         fromI = toJ = everyK = -1;
1723 
1724         expecting  = Expecting(ALPHA);
1725         expecting |= Expecting(NUMBER);
1726         expecting |= Expecting(SEMICOLON);
1727         }
1728     else if (expecting == Expecting(NUMBER))
1729         {
1730         if (strlen(tkn) == 1 && tkn[0] == '.')
1731             tempInt = numChar;
1732         else
1733             sscanf (tkn, "%d", &tempInt);
1734         if (tempInt <= 0 || tempInt > numChar)
1735             {
1736             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
1737             return (ERROR);
1738             }
1739         tempInt--;
1740         if (foundDash == YES)
1741             {
1742             if (fromI >= 0)
1743                 toJ = tempInt;
1744             else
1745                 {
1746                 MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
1747                 return (ERROR);
1748                 }
1749             foundDash = NO;
1750             }
1751         else if (foundSlash == YES)
1752             {
1753             tempInt++;
1754             if (tempInt <= 1)
1755                 {
1756                 MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
1757                 return (ERROR);
1758                 }
1759             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
1760                 everyK = tempInt;
1761             else
1762                 {
1763                 MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
1764                 return (ERROR);
1765                 }
1766             foundSlash = NO;
1767             }
1768         else
1769             {
1770             if (fromI >= 0 && toJ < 0)
1771                 {
1772                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1773                     return (ERROR);
1774                 fromI = tempInt;
1775                 }
1776             else if (fromI < 0 && toJ < 0)
1777                 {
1778                 fromI = tempInt;
1779                 }
1780             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
1781                 {
1782                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1783                     return (ERROR);
1784                 fromI = tempInt;
1785                 toJ = everyK = -1;
1786                 }
1787             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
1788                 {
1789                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1790                     return (ERROR);
1791                 fromI = tempInt;
1792                 toJ = everyK = -1;
1793                 }
1794             else
1795                 {
1796                 MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
1797                     {
1798                     return (ERROR);
1799                     }
1800                 }
1801 
1802             }
1803 
1804 
1805         expecting  = Expecting(ALPHA);
1806         expecting |= Expecting(NUMBER);
1807         expecting |= Expecting(SEMICOLON);
1808         expecting |= Expecting(DASH);
1809         expecting |= Expecting(BACKSLASH);
1810         }
1811     else if (expecting == Expecting(DASH))
1812         {
1813         foundDash = YES;
1814         expecting = Expecting(NUMBER);
1815         }
1816     else if (expecting == Expecting(BACKSLASH))
1817         {
1818         foundSlash = YES;
1819         expecting = Expecting(NUMBER);
1820         }
1821     else
1822         return (ERROR);
1823 
1824     return (NO_ERROR);
1825 }
1826 
1827 
DoCharStat(void)1828 int DoCharStat (void)
1829 {
1830     int         i, j, numDivs;
1831     char        tempName[100];
1832 
1833     if (defMatrix == NO)
1834         {
1835         MrBayesPrint ("%s   A character matrix must be defined first\n", spacer);
1836         return (ERROR);
1837         }
1838 
1839     if (numDefinedPartitions == 1)
1840         MrBayesPrint ("%s   1 character partition defined:\n", spacer, numDefinedPartitions);
1841     else
1842         MrBayesPrint ("%s   %d character partitions defined:\n", spacer, numDefinedPartitions);
1843     for (i=0; i<numDefinedPartitions; i++)
1844         {
1845         numDivs = GetNumPartDivisions (i);
1846         if (numDivs == 1)
1847             MrBayesPrint ("%s      Partition %d (\"%s\") does not divide the characters\n", spacer, i+1, partitionNames[i]);
1848         else
1849             MrBayesPrint ("%s      Partition %d (\"%s\") divides the characters into %d parts\n", spacer, i+1, partitionNames[i], numDivs);
1850         }
1851     MrBayesPrint ("%s      Current partition is \"%s\"\n", spacer, partitionNames[partitionNum]);
1852     MrBayesPrint ("\n");
1853 
1854     /* print out list of characters with information about each */
1855     MrBayesPrint ("%s   Showing character status:\n\n", spacer);
1856     MrBayesPrint ("%s                                                    Partition(s)\n", spacer);
1857     MrBayesPrint ("%s      #      Type      In/Out    Ambiguity Order  ", spacer);
1858     for (i=0; i<numDefinedPartitions; i++)
1859         MrBayesPrint (" %2d", i+1);
1860     MrBayesPrint ("\n");
1861     MrBayesPrint ("%s   -----------------------------------------------", spacer);
1862     for (i=0; i<numDefinedPartitions; i++)
1863         MrBayesPrint ("---");
1864     MrBayesPrint ("\n");
1865     for (i=0; i<numChar; i++)
1866         {
1867         MrBayesPrint ("%s   %4d -- ", spacer, i+1);
1868 
1869         if (charInfo[i].charType == DNA)
1870             MrBayesPrint ("   DNA");
1871         else if (charInfo[i].charType == RNA)
1872             MrBayesPrint ("   RNA");
1873         else if (charInfo[i].charType == PROTEIN)
1874             MrBayesPrint ("  Prot");
1875         else if (charInfo[i].charType == RESTRICTION)
1876             MrBayesPrint ("  Rest");
1877         else if (charInfo[i].charType == STANDARD)
1878             MrBayesPrint (" Stand");
1879         else if (charInfo[i].charType == CONTINUOUS)
1880             MrBayesPrint ("  Cont");
1881 
1882         if (charInfo[i].charType == DNA)
1883             MrBayesPrint ("   4");
1884         else if (charInfo[i].charType == RNA)
1885             MrBayesPrint ("   4");
1886         else if (charInfo[i].charType == PROTEIN)
1887             MrBayesPrint ("  20");
1888         else if (charInfo[i].charType == RESTRICTION)
1889             MrBayesPrint ("   2");
1890         else if (charInfo[i].charType == STANDARD)
1891             MrBayesPrint ("  %2d", charInfo[i].numStates);
1892         else if (charInfo[i].charType == CONTINUOUS)
1893             MrBayesPrint (" Inf");
1894 
1895         if (charInfo[i].isExcluded == NO)
1896             MrBayesPrint ("  Included");
1897         else
1898             MrBayesPrint ("  Excluded");
1899 
1900         if (charInfo[i].isMissAmbig == YES)
1901             MrBayesPrint ("  MissAmbig");
1902         else
1903             MrBayesPrint ("       None");
1904 
1905         if (charInfo[i].ctype == UNORD)
1906             MrBayesPrint (" Unord");
1907         else if (charInfo[i].ctype == ORD)
1908             MrBayesPrint ("   Ord");
1909         else if (charInfo[i].ctype == DOLLO)
1910             MrBayesPrint (" Dollo");
1911         else if (charInfo[i].ctype == IRREV)
1912             MrBayesPrint (" Irrev");
1913 
1914         MrBayesPrint ("  ");
1915 
1916         for (j=0; j<numDefinedPartitions; j++)
1917             MrBayesPrint (" %2d", partitionId[i][j]);
1918 
1919         /* MrBayesPrint ("%4d   ", charSet[i]);*/
1920 
1921         if (charInfo[i].pairsId > 0)
1922             {
1923             /* find paired character */
1924             for (j=0; j<numChar; j++)
1925                 {
1926                 if (i != j && charInfo[j].pairsId == charInfo[i].pairsId)
1927                     {
1928                     MrBayesPrint (" (coupled with %d)", j+1);
1929                     break;
1930                     }
1931                 }
1932             }
1933 
1934         MrBayesPrint ("\n");
1935 
1936         if (charInfo[i].bigBreakAfter == YES)
1937             {
1938             MrBayesPrint ("%s   ", spacer);
1939             MrBayesPrint ("     - - - - - - - - - - - - - - - - - - - -  \n");
1940             }
1941 
1942         /* we may want to pause */
1943         if (autoClose == NO)
1944             {
1945             if ((i+1) % 100 == 0)
1946                 {
1947                 MrBayesPrint ("%s   Hit return key to continue  ", spacer);
1948                 fflush (stdin);
1949                 if (fgets (tempName, 100, stdin) == NULL)
1950                     {
1951                     printf ("Error in function: %s at line: %d in file: %s", __func__, __LINE__, __FILE__);
1952                     }
1953                 }
1954             }
1955         }
1956 
1957     return (NO_ERROR);
1958 }
1959 
1960 
DoCitations(void)1961 int DoCitations (void)
1962 {
1963     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
1964     MrBayesPrint ("   Citations                                                                     \n");
1965     MrBayesPrint ("                                                                                 \n");
1966     MrBayesPrint ("   If you publish results obtained using MrBayes you may want to cite the        \n");
1967     MrBayesPrint ("   program using one of these papers:                                            \n");
1968     MrBayesPrint ("                                                                                 \n");
1969     MrBayesPrint ("      Huelsenbeck, J. P. and F. Ronquist. 2001. MRBAYES: Bayesian                \n");
1970     MrBayesPrint ("         inference of phylogeny. Bioinformatics 17:754-755.                      \n");
1971     MrBayesPrint ("      Ronquist, F. and J. P. Huelsenbeck. 2003. MRBAYES 3: Bayesian phylogenetic \n");
1972     MrBayesPrint ("         inference under mixed models. Bioinformatics 19:1572-1574.              \n");
1973     MrBayesPrint ("      Ronquist, F. et al. 2012. MRBAYES 3.2: Efficient Bayesian phylogenetic     \n");
1974     MrBayesPrint ("         inference and model selection across a large model space.               \n");
1975     MrBayesPrint ("         Syst. Biol. 61:539-542.                                                 \n");
1976     MrBayesPrint ("                                                                                 \n");
1977     MrBayesPrint ("   If you use the parallel abilities of the program, you may also want to cite   \n");
1978     MrBayesPrint ("                                                                                 \n");
1979     MrBayesPrint ("      Altekar, G., S. Dwarkadas, J. P. Huelsenbeck, and F. Ronquist. 2004.       \n");
1980     MrBayesPrint ("         Parallel Metropolis-coupled Markov chain Monte Carlo for Bayesian       \n");
1981     MrBayesPrint ("         phylogenetic inference. Bioinformatics 20:407-415.                      \n");
1982     MrBayesPrint ("                                                                                 \n");
1983     MrBayesPrint ("   If you use the BEAGLE library, the appropriate citation is                    \n");
1984     MrBayesPrint ("                                                                                 \n");
1985     MrBayesPrint ("      Ayres, D. L., A. Darling, D. J. Zwickl, P. Beerli, M. T. Holder, P. O.     \n");
1986     MrBayesPrint ("         J. P. Huelsenbeck, F. Ronquist, D. L. Swofford, M. P. Cummings, A.      \n");
1987     MrBayesPrint ("         Rambaut, and M. A. Suchard. 2012. BEAGLE: an application programming    \n");
1988     MrBayesPrint ("         interface for statistical phylogenetics. Syst. Biol. 61:170-173.        \n");
1989     MrBayesPrint ("                                                                                 \n");
1990     MrBayesPrint ("                                                                                 \n");
1991     MrBayesPrint ("   You should also cite other papers for different ideas that are implemented    \n");
1992     MrBayesPrint ("   in the program.  For example, the program performs Bayesian inference of      \n");
1993     MrBayesPrint ("   phylogeny, an idea that was first proposed in the following papers:           \n");
1994     MrBayesPrint ("                                                                                 \n");
1995     MrBayesPrint ("      Larget, B., and D. Simon. 1999. Markov chain Monte Carlo                   \n");
1996     MrBayesPrint ("         algorithms for the Bayesian analysis of phylogenetic trees.             \n");
1997     MrBayesPrint ("         Mol. Biol. Evol. 16:750-759.                                            \n");
1998     MrBayesPrint ("                                                                                 \n");
1999     MrBayesPrint ("      Li, S. 1996. Phylogenetic tree construction using Markov chain             \n");
2000     MrBayesPrint ("         Monte carlo. Ph. D. dissertation, Ohio State University, Columbus.      \n");
2001     MrBayesPrint ("                                                                                 \n");
2002     MrBayesPrint ("      Mau, B. 1996. Bayesian phylogenetic inference via Markov chain             \n");
2003     MrBayesPrint ("         Monte carlo methods. Ph. D. dissertation, University of                 \n");
2004     MrBayesPrint ("         Wisconsin, Madison.                                                     \n");
2005     MrBayesPrint ("                                                                                 \n");
2006     MrBayesPrint ("      Mau, B., and M. Newton. 1997. Phylogenetic inference for binary            \n");
2007     MrBayesPrint ("         data on dendrograms using Markov chain Monte Carlo. Journal of          \n");
2008     MrBayesPrint ("         Computational and Graphical Statistics 6:122-131.                       \n");
2009     MrBayesPrint ("                                                                                 \n");
2010     MrBayesPrint ("      Mau, B., M. Newton, and B. Larget. 1999. Bayesian phylogenetic             \n");
2011     MrBayesPrint ("         inference via Markov chain Monte carlo methods. Biometrics. 55:1-12.    \n");
2012     MrBayesPrint ("                                                                                 \n");
2013     MrBayesPrint ("      Newton, M., B. Mau, and B. Larget. 1999. Markov chain Monte Carlo          \n");
2014     MrBayesPrint ("         for the Bayesian analysis of evolutionary trees from aligned            \n");
2015     MrBayesPrint ("         molecular sequences. In Statistics in molecular biology (F. Seillier-   \n");
2016     MrBayesPrint ("         Moseiwitch, T. P. Speed, and M. Waterman, eds.). Monograph Series       \n");
2017     MrBayesPrint ("         of the Institute of Mathematical Statistics.                            \n");
2018     MrBayesPrint ("                                                                                 \n");
2019     MrBayesPrint ("      Rannala, B., and Z. Yang. 1996. Probability distribution of                \n");
2020     MrBayesPrint ("         molecular evolutionary trees: a new method of phylogenetic              \n");
2021     MrBayesPrint ("         inference. J. Mol. Evol. 43:304-311.                                    \n");
2022     MrBayesPrint ("                                                                                 \n");
2023     MrBayesPrint ("      Yang, Z., and B. Rannala. 1997. Bayesian phylogenetic inference            \n");
2024     MrBayesPrint ("         using DNA sequences: a Markov chain Monte carlo method. Molecular       \n");
2025     MrBayesPrint ("         Biology and Evolution. 14:717-724.                                      \n");
2026     MrBayesPrint ("                                                                                 \n");
2027     MrBayesPrint ("                                                                                 \n");
2028     MrBayesPrint ("   MrBayes uses Markov chain Monte Carlo (MCMC) to approximate the posterior     \n");
2029     MrBayesPrint ("   probability of trees.  MCMC was developed in the following papers:            \n");
2030     MrBayesPrint ("                                                                                 \n");
2031     MrBayesPrint ("      Metropolis, N., A. W. Rosenbluth, M. N. Rosenbluth, A. H. Teller,          \n");
2032     MrBayesPrint ("         and E. Teller. 1953. Equations of state calculations by fast            \n");
2033     MrBayesPrint ("         computing machines. J. Chem. Phys. 21:1087-1091.                        \n");
2034     MrBayesPrint ("                                                                                 \n");
2035     MrBayesPrint ("      Hastings, W. K. 1970. Monte Carlo sampling methods using Markov            \n");
2036     MrBayesPrint ("         chains and their applications. Biometrika 57:97-109.                    \n");
2037     MrBayesPrint ("                                                                                 \n");
2038     MrBayesPrint ("   In particular, MrBayes implements a variant of MCMC that was described by     \n");
2039     MrBayesPrint ("   Charles Geyer:                                                                \n");
2040     MrBayesPrint ("                                                                                 \n");
2041     MrBayesPrint ("      Geyer, C. J. 1991. Markov chain Monte Carlo maximum likelihood.            \n");
2042     MrBayesPrint ("         Pages 156-163 in Computing Science and Statistics: Proceed-             \n");
2043     MrBayesPrint ("         ings of the 23rd Symposium on the Interface. (E. M. Keramidas,          \n");
2044     MrBayesPrint ("         ed.). Fairfax Station: Interface Foundation.                            \n");
2045     MrBayesPrint ("                                                                                 \n");
2046     MrBayesPrint ("                                                                                 \n");
2047     MrBayesPrint ("   MrBayes implements a large number of DNA substitution models. These models    \n");
2048     MrBayesPrint ("   are of three different structures.  The \"4by4\" models are the usual flavor  \n");
2049     MrBayesPrint ("   of phylogenetic models.  The \"Doublet\" model was first proposed by          \n");
2050     MrBayesPrint ("                                                                                 \n");
2051     MrBayesPrint ("      Schoniger, M., and A. von Haeseler. 1994. A stochastic model and the       \n");
2052     MrBayesPrint ("         evolution of autocorrelated DNA sequences. Molecular Phylogenetics      \n");
2053     MrBayesPrint ("         and Evolution 3:240-247.                                                \n");
2054     MrBayesPrint ("                                                                                 \n");
2055     MrBayesPrint ("   The program also implements codon models.  Two papers, published back-to-back \n");
2056     MrBayesPrint ("   were the first to implement a codon model of DNA substitution in which the    \n");
2057     MrBayesPrint ("   substitution process is modelled on the codon, not on a site-by-site basis:   \n");
2058     MrBayesPrint ("                                                                                 \n");
2059     MrBayesPrint ("      Goldman, N., and Z. Yang. 1994. A codon-based model of nucleotide          \n");
2060     MrBayesPrint ("         substitution for protein coding DNA sequences. Molecular Biology        \n");
2061     MrBayesPrint ("         and Evolution. 11:725-736.                                              \n");
2062     MrBayesPrint ("                                                                                 \n");
2063     MrBayesPrint ("      Muse, S., and B. Gaut. 1994. A likelihood approach for comparing           \n");
2064     MrBayesPrint ("         synonymous and non-synonymous substitution rates, with application      \n");
2065     MrBayesPrint ("         to the chloroplast genome. Molecular Biology and Evolution.             \n");
2066     MrBayesPrint ("         11:715-724.                                                             \n");
2067     MrBayesPrint ("                                                                                 \n");
2068     MrBayesPrint ("   The program can be used to detect positively slected amino-acid sites using a \n");
2069     MrBayesPrint ("   full hierarchical Bayes analysis.  The method is based on the excellent paper \n");
2070     MrBayesPrint ("   by Nielsen and Yang:                                                          \n");
2071     MrBayesPrint ("                                                                                 \n");
2072     MrBayesPrint ("      Nielsen, R., and Z. Yang. 1998. Likelihood models for detecting            \n");
2073     MrBayesPrint ("         positively selected amino acid sites and applications to the HIV-1      \n");
2074     MrBayesPrint ("         envelope gene. Genetics. 148:929-936.                                   \n");
2075     MrBayesPrint ("                                                                                 \n");
2076     MrBayesPrint ("   The previous four papers describe three different structures for the          \n");
2077     MrBayesPrint ("   nucleotide models implemented in MrBayes--the four-by-four models, the        \n");
2078     MrBayesPrint ("   16-by-16 (doublet) models and the 64-by-64 (codon) models.  The program       \n");
2079     MrBayesPrint ("   implements three different substitution models within each model structure.   \n");
2080     MrBayesPrint ("   These include the nst=1 models:                                               \n");
2081     MrBayesPrint ("                                                                                 \n");
2082     MrBayesPrint ("      Jukes, T., and C. Cantor. 1969. Evolution of protein molecules.            \n");
2083     MrBayesPrint ("         Pages 21-132 in Mammalian Protein Metabolism. (H. Munro, ed.).          \n");
2084     MrBayesPrint ("         Academic Press, New York.                                               \n");
2085     MrBayesPrint ("                                                                                 \n");
2086     MrBayesPrint ("      Felsenstein, J. 1981. Evolutionary trees from DNA sequences: A             \n");
2087     MrBayesPrint ("         maximum likelihood approach. Journal of Molecular Evolution             \n");
2088     MrBayesPrint ("         17:368-376.                                                             \n");
2089     MrBayesPrint ("                                                                                 \n");
2090     MrBayesPrint ("   the nst=2 models:                                                             \n");
2091     MrBayesPrint ("                                                                                 \n");
2092     MrBayesPrint ("      Kimura, M. 1980. A simple method for estimating evolutionary rates         \n");
2093     MrBayesPrint ("         of base substitutions through comparative studies of nucleotide         \n");
2094     MrBayesPrint ("         sequences. Journal of Molecular Evolution. 16:111-120.                  \n");
2095     MrBayesPrint ("                                                                                 \n");
2096     MrBayesPrint ("      Hasegawa, M., T. Yano, and H. Kishino. 1984. A new molecular clock         \n");
2097     MrBayesPrint ("         of mitochondrial DNA and the evolution of Hominoids. Proc.              \n");
2098     MrBayesPrint ("         Japan Acad. Ser. B 60:95-98.                                            \n");
2099     MrBayesPrint ("                                                                                 \n");
2100     MrBayesPrint ("      Hasegawa, M., H. Kishino, and T. Yano. 1985. Dating the human-ape          \n");
2101     MrBayesPrint ("         split by a molecular clock of mitochondrial DNA. Journal of             \n");
2102     MrBayesPrint ("         Molecular Evolution 22:160-174.                                         \n");
2103     MrBayesPrint ("                                                                                 \n");
2104     MrBayesPrint ("   and the the nst=6 models:                                                     \n");
2105     MrBayesPrint ("                                                                                 \n");
2106     MrBayesPrint ("      Tavare, S. 1986. Some probabilistic and statisical problems on the         \n");
2107     MrBayesPrint ("         analysis of DNA sequences. Lect. Math. Life Sci. 17:57-86.              \n");
2108     MrBayesPrint ("         17:368-376.                                                             \n");
2109     MrBayesPrint ("                                                                                 \n");
2110     MrBayesPrint ("                                                                                 \n");
2111     MrBayesPrint ("   MrBayes implements a large number of amino-acid models.  These include:       \n");
2112     MrBayesPrint ("                                                                                 \n");
2113     MrBayesPrint ("      Poisson --                                                                 \n");
2114     MrBayesPrint ("                                                                                 \n");
2115     MrBayesPrint ("      Bishop, M.J., and A.E. Friday. 1987. Tetropad relationships: the           \n");
2116     MrBayesPrint ("         molecular evidence. Pp. 123-139 in Molecules and morphology in          \n");
2117     MrBayesPrint ("         evolution: conflict or compromise? (C. Patterson, ed.). Cambridge       \n");
2118     MrBayesPrint ("         University Press, Cambridge, England.                                   \n");
2119     MrBayesPrint ("                                                                                 \n");
2120     MrBayesPrint ("      Jones --                                                                   \n");
2121     MrBayesPrint ("                                                                                 \n");
2122     MrBayesPrint ("      Jones, D.T., W. R. Taylor, and J. M. Thornton. 1992. The rapid generation  \n");
2123     MrBayesPrint ("         of mutation data matrices from protein sequences. Comput. Appl.         \n");
2124     MrBayesPrint ("         Biosci. 8:275-282.                                                      \n");
2125     MrBayesPrint ("                                                                                 \n");
2126     MrBayesPrint ("      Dayhoff --                                                                 \n");
2127     MrBayesPrint ("                                                                                 \n");
2128     MrBayesPrint ("      Dayhoff, M.O., R.M. Schwartz, and B.C. Orcutt. 1978. A model of evol-      \n");
2129     MrBayesPrint ("         utionary change in proteins. Pp. 345-352 in Atlas of protein sequence   \n");
2130     MrBayesPrint ("         and structure. Vol. 5, Suppl. 3. National Biomedical Research           \n");
2131     MrBayesPrint ("          Foundation, Washington, D.C.                                           \n");
2132     MrBayesPrint ("                                                                                 \n");
2133     MrBayesPrint ("      Mtrev --                                                                   \n");
2134     MrBayesPrint ("                                                                                 \n");
2135     MrBayesPrint ("      Adachi, J. and M. Hasegawa. 1996. MOLPHY version 2.3: programs for         \n");
2136     MrBayesPrint ("         molecular phylogenetics based on maximum likelihood.  Computer Science  \n");
2137     MrBayesPrint ("         Monographs of Institute of Statistical Mathematics 28:1-150.            \n");
2138     MrBayesPrint ("                                                                                 \n");
2139     MrBayesPrint ("      Mtmam --                                                                   \n");
2140     MrBayesPrint ("                                                                                 \n");
2141     MrBayesPrint ("      Cao, Y., A. Janke, P.J. Waddell, M. Westerman, O. Takenaka, S. Murata,     \n");
2142     MrBayesPrint ("         N. Okada, S. Paabo, and M. Hasegawa. 1998. Conflict amongst individual  \n");
2143     MrBayesPrint ("         mitochondrial proteins in resolving the phylogeny of eutherian orders.  \n");
2144     MrBayesPrint ("         Journal of Molecular Evolution                                          \n");
2145     MrBayesPrint ("                                                                                 \n");
2146     MrBayesPrint ("      Yang, Z., R. Nielsen, and M. Hasegawa. 1998.  Models of amino acid         \n");
2147     MrBayesPrint ("         substitution and applications to mitochondrial protein evolution        \n");
2148     MrBayesPrint ("         Molecular Biology and Evolution 15:1600-1611.                           \n");
2149     MrBayesPrint ("                                                                                 \n");
2150     MrBayesPrint ("      WAG --                                                                     \n");
2151     MrBayesPrint ("                                                                                 \n");
2152     MrBayesPrint ("      Whelan, S. and Goldman, N. 2001. A general empirical model of protein      \n");
2153     MrBayesPrint ("         evolution derived from multiple protein families using a maximum-       \n");
2154     MrBayesPrint ("         likelihood approach. Molecular Biology and Evolution 18:691-699.        \n");
2155     MrBayesPrint ("                                                                                 \n");
2156     MrBayesPrint ("      Rtrev --                                                                   \n");
2157     MrBayesPrint ("                                                                                 \n");
2158     MrBayesPrint ("      Dimmic M.W., J.S. Rest, D.P. Mindell, and D. Goldstein. 2002. RArtREV:     \n");
2159     MrBayesPrint ("         An amino acid substitution matrix for inference of retrovirus and       \n");
2160     MrBayesPrint ("         reverse transcriptase phylogeny. Journal of Molecular Evolution         \n");
2161     MrBayesPrint ("         55: 65-73.                                                              \n");
2162     MrBayesPrint ("                                                                                 \n");
2163     MrBayesPrint ("      Cprev --                                                                   \n");
2164     MrBayesPrint ("                                                                                 \n");
2165     MrBayesPrint ("      Adachi, J., P. Waddell, W. Martin, and M. Hasegawa. 2000. Plastid          \n");
2166     MrBayesPrint ("         genome phylogeny and a model of amino acid substitution for proteins    \n");
2167     MrBayesPrint ("         encoded by chloroplast DNA. Journal of Molecular Evolution              \n");
2168     MrBayesPrint ("         50:348-358.                                                             \n");
2169     MrBayesPrint ("                                                                                 \n");
2170     MrBayesPrint ("      Blosum --                                                                  \n");
2171     MrBayesPrint ("                                                                                 \n");
2172     MrBayesPrint ("      Henikoff, S., and J. G. Henikoff. 1992. Amino acid substitution            \n");
2173     MrBayesPrint ("         matrices from protein blocks. Proc. Natl. Acad. Sci., U.S.A.            \n");
2174     MrBayesPrint ("         89:10915-10919. The matrix implemented in MrBayes is Blosum62.          \n");
2175     MrBayesPrint ("                                                                                 \n");
2176     MrBayesPrint ("      Vt --                                                                      \n");
2177     MrBayesPrint ("                                                                                 \n");
2178     MrBayesPrint ("      Muller, T., and M. Vingron. 2000. Modeling amino acid replacement.         \n");
2179     MrBayesPrint ("         Journal of Computational Biology 7:761-776.                             \n");
2180     MrBayesPrint ("                                                                                 \n");
2181     MrBayesPrint ("      LG --                                                                      \n");
2182     MrBayesPrint ("                                                                                 \n");
2183     MrBayesPrint ("      Le, Si Q. & Gascuel, O. 2008 An improved general amino- acid replacement   \n");
2184     MrBayesPrint ("         matrix. Mol. Biol. Evol. 25, 1307-1320.                                 \n");
2185     MrBayesPrint ("                                                                                 \n");
2186     MrBayesPrint ("   MrBayes implements a simple Jukes-Cantor-like model for restriction sites     \n");
2187     MrBayesPrint ("   and other binary data.  A problem with some of these data is that there is a  \n");
2188     MrBayesPrint ("   coding bias, such that certain characters are missing from any observable data\n");
2189     MrBayesPrint ("   matrix.  It is impossible, for instance, to observe restriction sites that are\n");
2190     MrBayesPrint ("   absent in all the studied taxa.  However, MrBayes corrects for this coding    \n");
2191     MrBayesPrint ("   bias according to an idea described in                                        \n");
2192     MrBayesPrint ("                                                                                 \n");
2193     MrBayesPrint ("      Felsenstein, J. 1992. Phylogenies from restriction sites: A maximum-       \n");
2194     MrBayesPrint ("         likelihood approach. Evolution 46:159-173.                              \n");
2195     MrBayesPrint ("                                                                                 \n");
2196     MrBayesPrint ("                                                                                 \n");
2197     MrBayesPrint ("   The model used by MrBayes for 'standard' or morphological data is based on    \n");
2198     MrBayesPrint ("   the ideas originally presented by                                             \n");
2199     MrBayesPrint ("                                                                                 \n");
2200     MrBayesPrint ("      Lewis, P. O. 2001. A likelihood approach to estimating phylogeny from      \n");
2201     MrBayesPrint ("         discrete morphological character data. Systematic Biology 50:913-925.   \n");
2202     MrBayesPrint ("                                                                                 \n");
2203     MrBayesPrint ("                                                                                 \n");
2204     MrBayesPrint ("   For both DNA sequence and amino-acid data, the program allows rates to change \n");
2205     MrBayesPrint ("   under a covarion-like model, first described by Tuffley and Steel             \n");
2206     MrBayesPrint ("                                                                                 \n");
2207     MrBayesPrint ("      Tuffley, C., and M. Steel. 1998. Modeling the covarion hypothesis          \n");
2208     MrBayesPrint ("         of nucleotide substitution. Mathematical Biosciences 147:63-91.         \n");
2209     MrBayesPrint ("                                                                                 \n");
2210     MrBayesPrint ("   and implemented by Huelsenbeck (2002)                                         \n");
2211     MrBayesPrint ("                                                                                 \n");
2212     MrBayesPrint ("      Huelsenbeck, J. P. 2002. Testing a covariotide model of DNA sub-           \n");
2213     MrBayesPrint ("         stitution. Molecular Biology and Evolution 19(5):698-707.               \n");
2214     MrBayesPrint ("                                                                                 \n");
2215     MrBayesPrint ("   Galtier (2001) implements a different variant of the covarion model in a      \n");
2216     MrBayesPrint ("   paper that is worth reading:                                                  \n");
2217     MrBayesPrint ("                                                                                 \n");
2218     MrBayesPrint ("      Galtier, N. 2001. Maximum-likelihood phylogenetic analysis under a         \n");
2219     MrBayesPrint ("         covarion-like model. Mol. Biol. Evol. 18:866-873.                       \n");
2220     MrBayesPrint ("                                                                                 \n");
2221     MrBayesPrint ("                                                                                 \n");
2222     MrBayesPrint ("   A number of models are available that allow rates to vary across the          \n");
2223     MrBayesPrint ("   characters.  The program implements the proportion of invariable sites model  \n");
2224     MrBayesPrint ("   and two variants of gamma distributed rate variation.  Yang\'s (1993) paper   \n");
2225     MrBayesPrint ("   is a good one to cite for implementing a gamma-distributed rates model.       \n");
2226     MrBayesPrint ("   In the 1994 paper he provides a way to approximate the continuous gamma       \n");
2227     MrBayesPrint ("   distribution:                                                                 \n");
2228     MrBayesPrint ("                                                                                 \n");
2229     MrBayesPrint ("      Yang, Z. 1993. Maximum likelihood estimation of phylogeny from DNA         \n");
2230     MrBayesPrint ("         sequences when substitution rates differ over sites. Molecular          \n");
2231     MrBayesPrint ("         Biology and Evolution 10:1396-1401.                                     \n");
2232     MrBayesPrint ("                                                                                 \n");
2233     MrBayesPrint ("      Yang, Z. 1994. Maximum likelihood phylogenetic estimation from DNA         \n");
2234     MrBayesPrint ("         sequences with variable rates over sites: Approximate methods.          \n");
2235     MrBayesPrint ("         Journal of Molecular Evolution 39:306-314.                              \n");
2236     MrBayesPrint ("                                                                                 \n");
2237     MrBayesPrint ("   The program also implements Yang\'s autocorrelated gamma model.  In this      \n");
2238     MrBayesPrint ("   model, the rate at one site depends to some extent on the rate at an adjacent \n");
2239     MrBayesPrint ("   site.  The appropriate citation for this model is:                            \n");
2240     MrBayesPrint ("                                                                                 \n");
2241     MrBayesPrint ("      Yang, Z. 1995. A space-time process model for the evolution of             \n");
2242     MrBayesPrint ("         DNA sequences. Genetics 139:993-1005.                                   \n");
2243     MrBayesPrint ("                                                                                 \n");
2244     MrBayesPrint ("                                                                                 \n");
2245     MrBayesPrint ("   The following two papers show how ancestral states on a tree can be           \n");
2246     MrBayesPrint ("   reconstructed.  The Yang et al. paper implements an empirical Bayes approach  \n");
2247     MrBayesPrint ("   while Huelsenbeck and Bollback use a pure, hierarchical Bayes approach. The   \n");
2248     MrBayesPrint ("   method used in MrBayes is the latter, since it integrates over uncertainty in \n");
2249     MrBayesPrint ("   model parameters.                                                             \n");
2250     MrBayesPrint ("                                                                                 \n");
2251     MrBayesPrint ("      Yang, Z., S. Kumar, and M. Nei. 1995. A new method of inference of         \n");
2252     MrBayesPrint ("         ancestral nucleotide and amino acid sequences. Genetics 141:1641        \n");
2253     MrBayesPrint ("         1650.                                                                   \n");
2254     MrBayesPrint ("                                                                                 \n");
2255     MrBayesPrint ("      Huelsenbeck, J. P., and J. P. Bollback. 2001. Empirical and hier-          \n");
2256     MrBayesPrint ("         archical Bayesian estimation of ancestral states. Systematic            \n");
2257     MrBayesPrint ("         Biology 50:351-366.                                                     \n");
2258     MrBayesPrint ("                                                                                 \n");
2259     MrBayesPrint ("   You may also want to consult a more recent review of Bayesian reconstruction  \n");
2260     MrBayesPrint ("   of ancestral states and character evolution:                                  \n");
2261     MrBayesPrint ("                                                                                 \n");
2262     MrBayesPrint ("      Ronquist, F. 2004. Bayesian inference of character evolution. Trends in    \n");
2263     MrBayesPrint ("         Ecology and Evolution 19: 475-481.                                      \n");
2264     MrBayesPrint ("                                                                                 \n");
2265     MrBayesPrint ("                                                                                 \n");
2266     MrBayesPrint ("   MrBayes allows you to analyze gene tree - species tree problems using the     \n");
2267     MrBayesPrint ("   multi-species coalescent approach originally proposed by Edwards et al:       \n");
2268     MrBayesPrint ("                                                                                 \n");
2269     MrBayesPrint ("      Edwards, S., L. Liu, and D. Pearl. 2007. High-resolution species trees     \n");
2270     MrBayesPrint ("         without concatenation. Proc. Natl. Acad. Sci. USA 104: 5936-5941.       \n");
2271     MrBayesPrint ("                                                                                 \n");
2272     MrBayesPrint ("                                                                                 \n");
2273     MrBayesPrint ("   The program implements an incredibly parameter rich model, first described by \n");
2274     MrBayesPrint ("   Tuffley and Steel (1997), that orders trees in the same way as the so-called  \n");
2275     MrBayesPrint ("   parsimony method of phylogenetic inference.  The appropriate citation is:     \n");
2276     MrBayesPrint ("                                                                                 \n");
2277     MrBayesPrint ("      Tuffley, C., and M. Steel. 1997. Links between maximum likelihood          \n");
2278     MrBayesPrint ("         and maximum parsimony under a simple model of site substitution.        \n");
2279     MrBayesPrint ("         Bull. Math. Bio. 59:581-607.                                            \n");
2280     MrBayesPrint ("                                                                                 \n");
2281     MrBayesPrint ("                                                                                 \n");
2282     MrBayesPrint ("   MrBayes implements three relaxed clock models: the Compound Poisson Process   \n");
2283     MrBayesPrint ("   (CPP), the Thorne-Kishino 2002 (TK02), and the Independent Gamma Rates (IGR)  \n");
2284     MrBayesPrint ("   models.  The CPP model was first described by Huelsenbeck et al. (2000).  It  \n");
2285     MrBayesPrint ("   is an autocorrelated discrete model of rate variation over time.  Instead of  \n");
2286     MrBayesPrint ("   the modified gamma distribution originally proposed for the rate multipliers, \n");
2287     MrBayesPrint ("   MrBayes uses a lognormal distribution.  The extensions necessary to sample    \n");
2288     MrBayesPrint ("   over tree space under this model are original to MrBayes; the original paper  \n");
2289     MrBayesPrint ("   only considered fixed trees.                                                  \n");
2290     MrBayesPrint ("                                                                                 \n");
2291     MrBayesPrint ("   The TK02 model was first described by Thorne and Kishino (2002), and is a     \n");
2292     MrBayesPrint ("   variant of a model presented by them earlier (Thorne et al., 1998).  It is an \n");
2293     MrBayesPrint ("   autocorrelated continuous model, in which rates vary according to a lognormal \n");
2294     MrBayesPrint ("   distribution.  Specifically, the rate of a descendant node is assumed to      \n");
2295     MrBayesPrint ("   be drawn from a lognormal distribution with the mean being the rate of the    \n");
2296     MrBayesPrint ("   ancestral node, and the variance being proportional to the length of the      \n");
2297     MrBayesPrint ("   branch separating the nodes (measured in terms of expected substitutions per  \n");
2298     MrBayesPrint ("   site at the base rate of the clock).                                          \n");
2299     MrBayesPrint ("                                                                                 \n");
2300     MrBayesPrint ("   The final relaxed clock model is the IGR model, in which branch rates are     \n");
2301     MrBayesPrint ("   modeled as being drawn independently from gamma distributions.  The model was \n");
2302     MrBayesPrint ("   originally described in the literature as the 'White Noise' model by Lepage   \n");
2303     MrBayesPrint ("   et al. (2007), but the original MrBayes implementation predates that paper.   \n");
2304     MrBayesPrint ("   The IGR model is closely related to the uncorrelated gamma model presented    \n");
2305     MrBayesPrint ("   originally by Drummond et al. (2006), but it is more elegant in that it truly \n");
2306     MrBayesPrint ("   lacks time structure.  See Lepage et al. (2007) for details.                  \n");
2307     MrBayesPrint ("                                                                                 \n");
2308     MrBayesPrint ("      Huelsenbeck, J. P., B. Larget, and D. Swofford. 2000. A compound Poisson   \n");
2309     MrBayesPrint ("         process for relaxing the molecular clock. Genetics 154: 1879-1892.      \n");
2310     MrBayesPrint ("                                                                                 \n");
2311     MrBayesPrint ("      Thorne, J. L., H. Kishino, and I. S. Painter. 1998. Estimating the rate    \n");
2312     MrBayesPrint ("         of evolution of the rate of molecular evolution. Mol. Biol. Evol.       \n");
2313     MrBayesPrint ("         15: 1647-1657.                                                          \n");
2314     MrBayesPrint ("                                                                                 \n");
2315     MrBayesPrint ("      Thorne, J. L., and H. Kishino. 2002. Divergence time and evolutionary      \n");
2316     MrBayesPrint ("         rate estimation with multilocus data. Syst. Biol. 51: 689-702.          \n");
2317     MrBayesPrint ("                                                                                 \n");
2318     MrBayesPrint ("      Drummond, A. J., S. Y. W. Ho, M. J. Phillips, and A. Rambaut. 2006.        \n");
2319     MrBayesPrint ("         Relaxed phylogenetics and dating with confidence. PLoS Biology          \n");
2320     MrBayesPrint ("         4: 699-710.                                                             \n");
2321     MrBayesPrint ("                                                                                 \n");
2322     MrBayesPrint ("      Lepage, T., D. Bryant, H. Philippe, and N. Lartillot. 2007. A general      \n");
2323     MrBayesPrint ("         comparison of relaxed molecular clock models. Mol. Biol. Evol.          \n");
2324     MrBayesPrint ("         24: 2669-2680.                                                          \n");
2325     MrBayesPrint ("                                                                                 \n");
2326     MrBayesPrint ("                                                                                 \n");
2327     MrBayesPrint ("   The standard tree proposals used by MrBayes are described by Lakner et al.    \n");
2328     MrBayesPrint ("   (2008).  The parsimony-biased tree proposals are still undescribed, although  \n");
2329     MrBayesPrint ("   a rough outline of the idea is presented in the same paper.                   \n");
2330     MrBayesPrint ("                                                                                 \n");
2331     MrBayesPrint ("      Lakner, C., P. van der Mark, J. P. Huelsenbeck, B. Larget, and F. Ronquist.\n");
2332     MrBayesPrint ("         2008. Efficiency of Markov chain Monte Carlo tree proposals in Bayesian \n");
2333     MrBayesPrint ("         phylogenetics. Syst. Biol. 57: 86-103.                                  \n");
2334     MrBayesPrint ("                                                                                 \n");
2335     MrBayesPrint ("                                                                                 \n");
2336     MrBayesPrint ("   The topology convergence diagnostic used by MrBayes, the average standard     \n");
2337     MrBayesPrint ("   deviation of split frequencies, is described by Lakner et al. (2008).         \n");
2338     MrBayesPrint ("   The potential scale reduction factor, the diagnostic used by MrBayes for      \n");
2339     MrBayesPrint ("   continous parameters, was first proposed by Gelman and Rubin (1992).  The     \n");
2340     MrBayesPrint ("   auto-tuning mechanism used in MrBayes is based on a paper by Roberts and      \n");
2341     MrBayesPrint ("   Rosenthal (2009).                                                             \n");
2342     MrBayesPrint ("                                                                                 \n");
2343     MrBayesPrint ("      Gelman, A., and D. B. Rubin. 1992. Inference from iterative simulation     \n");
2344     MrBayesPrint ("         using multiple sequences. Statistical Science 7: 457-472.               \n");
2345     MrBayesPrint ("         Bull. Math. Bio. 59:581-607.                                            \n");
2346     MrBayesPrint ("                                                                                 \n");
2347     MrBayesPrint ("      Lakner, C., P. van der Mark, J. P. Huelsenbeck, B. Larget, and F. Ronquist.\n");
2348     MrBayesPrint ("         2008. Efficiency of Markov chain Monte Carlo tree proposals in Bayesian \n");
2349     MrBayesPrint ("         phylogenetics. Syst. Biol. 57: 86-103.                                  \n");
2350     MrBayesPrint ("                                                                                 \n");
2351     MrBayesPrint ("      Roberts, G. O., and J. S. Rosenthal. 2009. Examples of adaptive            \n");
2352     MrBayesPrint ("         MCMC. Journal of Compuational and Graphical Statistics 18: 349-367.     \n");
2353     MrBayesPrint ("                                                                                 \n");
2354     MrBayesPrint ("                                                                                 \n");
2355     MrBayesPrint ("   The harmonic mean estimator of model likelihoods, used for Bayes factor       \n");
2356     MrBayesPrint ("   testing, was discussed by Newton and Raftery (1996).  The more accurate       \n");
2357     MrBayesPrint ("   stepping-stone algorithm was first proposed by Xie et al. (2011).  The paper  \n");
2358     MrBayesPrint ("   by Lartillot and Philippe (2006) presents an interesting discussion of the    \n");
2359     MrBayesPrint ("   shortcomings of the harmonic mean estimator and describes thermodynamic       \n");
2360     MrBayesPrint ("   integration, a technique that is similar to the stepping-stone algorithm.     \n");
2361     MrBayesPrint ("                                                                                 \n");
2362     MrBayesPrint ("      Newton, M. A., and A. E. Raftery. 1994. Approcimate Bayesian inference     \n");
2363     MrBayesPrint ("         with the weighted likelihood bootstrap. J. R. Stat. Soc. B. 56. 3-48.   \n");
2364     MrBayesPrint ("                                                                                 \n");
2365     MrBayesPrint ("      Lartillot, N., and H. Philippe. 2006. Computing Bayes factors using        \n");
2366     MrBayesPrint ("         thermodynamic integration. Syst. Biol. 55: 195-207.                     \n");
2367     MrBayesPrint ("                                                                                 \n");
2368     MrBayesPrint ("      Xie, W., P. O. Lewis, Y. Fan, L. Kuo, and M.-H. Chen. 2011. Improving      \n");
2369     MrBayesPrint ("         marginal likelihood estimation for Bayesian phylogenetic model          \n");
2370     MrBayesPrint ("         selection. Syst. Biol. 60: 150-160.                                     \n");
2371     MrBayesPrint ("                                                                                 \n");
2372     MrBayesPrint ("                                                                                 \n");
2373     MrBayesPrint ("   For unconstrained branch lengths, MrBayes implements the compound Dirichlet   \n");
2374     MrBayesPrint ("   priors for branch lengths described by Rannala et al. (2012) and Zhang et al. \n");
2375     MrBayesPrint ("   (2012).  Compared with the i.i.d. exponential and uniform priors for branch   \n");
2376     MrBayesPrint ("   lengths in the previous versions of MrBayes, the Dirichlet priors appear more \n");
2377     MrBayesPrint ("   reasonable and may avoid the problem of extremely long trees, as discussed    \n");
2378     MrBayesPrint ("   by Brown et al. (2010) and Marshall (2010).  The two-exponential prior on     \n");
2379     MrBayesPrint ("   internal and external branch lengths described by Yang & Rannala (2005) and   \n");
2380     MrBayesPrint ("   Yang (2007) is also implemented in this version.                              \n");
2381     MrBayesPrint ("                                                                                 \n");
2382     MrBayesPrint ("      Brown, J. M., S. M. Hedtke, A. R. Lemmon, and E. M. Lemmon. 2010. When     \n");
2383     MrBayesPrint ("         trees  grow too long: investigating the causes of highly inaccurate     \n");
2384     MrBayesPrint ("         Bayesian branch-length estimates. Syst. Biol. 59:145-161.               \n");
2385     MrBayesPrint ("                                                                                 \n");
2386     MrBayesPrint ("      Marshall, D. C. 2010. Cryptic failure of partitioned Bayesian phylogenetic \n");
2387     MrBayesPrint ("         analyses: lost in the land of long trees. Syst. Biol. 59:108-117.       \n");
2388     MrBayesPrint ("                                                                                 \n");
2389     MrBayesPrint ("      Rannala, B., T. Zhu, and Z. Yang. 2012. Tail paradox, partial              \n");
2390     MrBayesPrint ("         identifiability and influential priors in Bayesian branch length        \n");
2391     MrBayesPrint ("         inference. Mol. Biol. Evol. 29:325-335.                                 \n");
2392     MrBayesPrint ("                                                                                 \n");
2393     MrBayesPrint ("      Zhang, C., B. Rannala, and Z. Yang. 2012. Robustness of compound Dirichlet \n");
2394     MrBayesPrint ("         priors for Bayesian inference of branch lengths. Syst. Biol. 61:779-784.\n");
2395     MrBayesPrint ("                                                                                 \n");
2396     MrBayesPrint ("      Yang, Z. 2007. Fair-balance paradox, star-tree paradox and Bayesian        \n");
2397     MrBayesPrint ("         phylogenetics. Mol. Biol. Evol. 24:1639-1655.                           \n");
2398     MrBayesPrint ("                                                                                 \n");
2399     MrBayesPrint ("      Yang, Z., and B. Rannala. 2005. Branch-length prior influences Bayesian    \n");
2400     MrBayesPrint ("         posterior probability of phylogeny. Syst. Biol. 54:455-470.             \n");
2401     MrBayesPrint ("                                                                                 \n");
2402     MrBayesPrint ("                                                                                 \n");
2403     MrBayesPrint ("                                                                                 \n");
2404     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
2405 
2406     return (NO_ERROR);
2407 }
2408 
2409 
DoConstraint(void)2410 int DoConstraint (void)
2411 {
2412     int         i, howMany;
2413     int         *tset;
2414 
2415     if (constraintType == PARTIAL)
2416         tset=tempSetNeg;
2417     else
2418         tset=tempSet;
2419 
2420     /* add set to tempSet */
2421     if (fromI >= 0 && toJ < 0)
2422         {
2423         if (AddToGivenSet (fromI, toJ, everyK, 1, tset) == ERROR)
2424             return (ERROR);
2425         }
2426     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
2427         {
2428         if (AddToGivenSet (fromI, toJ, everyK, 1, tset) == ERROR)
2429             return (ERROR);
2430         }
2431     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
2432         {
2433         if (AddToGivenSet (fromI, toJ, everyK, 1, tset) == ERROR)
2434             return (ERROR);
2435         }
2436 
2437     /* check that this is not a stupid constraint */
2438     howMany = 0;
2439     for (i=0; i<numTaxa; i++)
2440         if (tempSet[i] != 0)
2441             howMany++;
2442 
2443     if (howMany == 0)
2444         {
2445         MrBayesPrint ("%s   This constraint does not include any taxa and will not be defined\n", spacer);
2446         return (ERROR);
2447         }
2448 
2449     if (constraintType == HARD)
2450         {
2451         if (howMany == numTaxa)
2452             {
2453             /* We allow this so we can report states from and calibrate root */
2454             }
2455 
2456         } /*end constraintType == HARD */
2457     else if (constraintType == PARTIAL)
2458         {
2459         if (howMany == 1)
2460             {
2461             MrBayesPrint ("%s   This partial constraint includes only one taxon. It is always satisfied and will not be defined.\n", spacer);
2462             return (ERROR);
2463             }
2464 
2465         howMany = 0;
2466         for (i=0; i<numTaxa; i++)
2467             {
2468             if (tempSetNeg[i] != 0)
2469                 {
2470                 howMany++;
2471                 if (tempSetNeg[i] == tempSet[i])
2472                     {
2473                     MrBayesPrint ("%s   Two sets of taxa in partial constraint are not allowed to intersect. Constraint will not be defined\n", spacer);
2474                     return (ERROR);
2475                     }
2476                 }
2477             }
2478         if (howMany == 0)
2479             {
2480             MrBayesPrint ("%s   This partial constraint does not include any taxa in the second set and will not be defined\n", spacer);
2481             return (ERROR);
2482             }
2483         }
2484     else if (constraintType == NEGATIVE)
2485         {
2486         if (howMany == 1)
2487             {
2488             MrBayesPrint ("%s   Negative constraint should include more than one taxon. Constraint will not be defined\n", spacer);
2489             return (ERROR);
2490             }
2491         }
2492 
2493     /* add name to constraintNames */
2494     if (AddString (&constraintNames, numDefinedConstraints, tempSetName) == ERROR)
2495         {
2496         MrBayesPrint ("%s   Problem adding constraint %s to list\n", spacer, tempSetName);
2497         return (ERROR);
2498         }
2499 
2500     /* store tempSet */
2501     AddBitfield (&definedConstraint, numDefinedConstraints, tempSet, numTaxa);
2502     if (constraintType == PARTIAL)
2503         {
2504         AddBitfield (&definedConstraintTwo, numDefinedConstraints, tempSetNeg, numTaxa);
2505         }
2506     else
2507         {
2508         definedConstraintTwo = (BitsLong **) SafeRealloc ((void *)(definedConstraintTwo), ((size_t)numDefinedConstraints+1)*sizeof(BitsLong *));
2509         if (definedConstraintTwo==NULL)
2510             return ERROR;
2511         definedConstraintTwo[numDefinedConstraints]=NULL;
2512         }
2513 
2514     /* add a default node calibration */
2515     nodeCalibration = (Calibration *) SafeRealloc ((void *)nodeCalibration, ((size_t)numDefinedConstraints+1)*sizeof(Calibration));
2516     nodeCalibration[numDefinedConstraints].prior            = defaultCalibration.prior;
2517     nodeCalibration[numDefinedConstraints].priorParams[0]   = defaultCalibration.priorParams[0];
2518     nodeCalibration[numDefinedConstraints].priorParams[1]   = defaultCalibration.priorParams[1];
2519     nodeCalibration[numDefinedConstraints].priorParams[2]   = defaultCalibration.priorParams[2];
2520     nodeCalibration[numDefinedConstraints].min              = defaultCalibration.min;
2521     nodeCalibration[numDefinedConstraints].max              = defaultCalibration.max;
2522     nodeCalibration[numDefinedConstraints].LnPriorProb      = defaultCalibration.LnPriorProb;
2523     nodeCalibration[numDefinedConstraints].LnPriorRatio     = defaultCalibration.LnPriorRatio;
2524     strcpy(nodeCalibration[numDefinedConstraints].name, defaultCalibration.name);
2525 
2526     /* increment number of defined constraints */
2527     numDefinedConstraints++;
2528 
2529     /* reallocate and initialize space for activeConstraints */
2530     for (i=0; i<numCurrentDivisions; i++)
2531         {
2532         modelParams[i].activeConstraints = (int *) SafeRealloc((void *)(modelParams[i].activeConstraints), (size_t)numDefinedConstraints*sizeof(int));
2533         modelParams[i].activeConstraints[numDefinedConstraints-1] = NO;
2534         }
2535 
2536     /* reallocate and initialize space for tempActiveConstraints */
2537     tempActiveConstraints = (int *) SafeRealloc((void *)(tempActiveConstraints), (size_t)numDefinedConstraints*sizeof(int));
2538     tempActiveConstraints[numDefinedConstraints-1] = NO;
2539 
2540     definedConstraintsType = (enum ConstraintType *) SafeRealloc((void *)(definedConstraintsType), (size_t)numDefinedConstraints*sizeof(enum ConstraintType));
2541     if (definedConstraintsType==NULL)
2542         return ERROR;
2543     definedConstraintsType[numDefinedConstraints-1] = constraintType;
2544 
2545     definedConstraintPruned = (BitsLong **) SafeRealloc ((void *)(definedConstraintPruned), (size_t)numDefinedConstraints*sizeof(BitsLong *));
2546     if (definedConstraintPruned==NULL)
2547         return ERROR;
2548     definedConstraintPruned[numDefinedConstraints-1]=NULL;
2549 
2550     definedConstraintTwoPruned = (BitsLong **) SafeRealloc ((void *)(definedConstraintTwoPruned), (size_t)numDefinedConstraints*sizeof(BitsLong *));
2551     if (definedConstraintTwoPruned==NULL)
2552         return ERROR;
2553     definedConstraintTwoPruned[numDefinedConstraints-1]=NULL;
2554 
2555     /* show taxset (for debugging) */
2556     // for (i=0; i<numTaxa; i++)
2557     //     MrBayesPrint ("%4d  %4d\n", i+1, taxaInfo[i].constraints[numDefinedConstraints-1]);
2558 
2559     return (NO_ERROR);
2560 }
2561 
2562 
DoConstraintParm(char * parmName,char * tkn)2563 int DoConstraintParm (char *parmName, char *tkn)
2564 {
2565     int         i, index, tempInt;
2566     MrBFlt      tempD;
2567     static int  *tempSetCurrent;
2568 
2569     if (defMatrix == NO)
2570         {
2571         MrBayesPrint ("%s   A matrix must be specified before constraints can be defined\n", spacer);
2572         return (ERROR);
2573         }
2574 
2575     if (expecting == Expecting(PARAMETER))
2576         {
2577         if (!strcmp(parmName, "Xxxxxxxxxx"))
2578             {
2579             /* check size of constraint name */
2580             if (strlen(tkn) > 99)
2581                 {
2582                 MrBayesPrint ("%s   Constraint name is too long\n", spacer);
2583                 return (ERROR);
2584                 }
2585 
2586             /* check to see if the name has already been used as a constraint */
2587             if (numDefinedConstraints > 0)
2588                 {
2589                 if (CheckString (constraintNames, numDefinedConstraints, tkn, &index) == ERROR)
2590                     {
2591                     /* an ERROR returned if the constraint name has not been used. we _want_ to be here */
2592                     }
2593                 else
2594                     {
2595                     MrBayesPrint ("%s   Constraint name '%s' has been used previously\n", spacer, tkn);
2596                     return (ERROR);
2597                     }
2598                 }
2599 
2600             /* copy the name to the temporary constraint names string */
2601             strcpy (tempSetName, tkn);
2602 
2603             /* clear tempSet */
2604             for (i=0; i<numTaxa; i++)
2605                 tempSet[i] = 0;
2606 
2607             constraintType = HARD; /* set default constrain type */
2608             tempSetCurrent=tempSet;
2609             fromI = toJ = everyK = -1;
2610             foundDash = foundSlash = NO;
2611             MrBayesPrint ("%s   Defining constraint called '%s'\n", spacer, tkn);
2612             foundExp = NO;
2613             foundFirst = YES;
2614             foundEqual = NO;
2615             isNegative = NO;
2616             foundColon = NO;
2617             expecting = Expecting(ALPHA);
2618             expecting |= Expecting(NUMBER);
2619             expecting |= Expecting(DASH);
2620             expecting |= Expecting(EQUALSIGN);
2621             }
2622         else
2623             return (ERROR);
2624         }
2625     else if (expecting == Expecting(EQUALSIGN))
2626         {
2627         foundEqual = YES;
2628         expecting  = Expecting(ALPHA);
2629         expecting |= Expecting(NUMBER);
2630         }
2631     else if (expecting == Expecting(LEFTPAR))
2632         {
2633         isNegative = NO;
2634         expecting = Expecting(NUMBER);
2635         expecting |= Expecting(DASH);
2636         }
2637     else if (expecting == Expecting(RIGHTPAR))
2638         {
2639         isNegative = NO;
2640         foundExp = NO;
2641         expecting = Expecting(EQUALSIGN);
2642         }
2643     else if (expecting == Expecting(DASH))
2644         {
2645         if (foundExp == YES)
2646             isNegative = YES;
2647         else
2648             foundDash = YES;
2649         expecting = Expecting(NUMBER);
2650         }
2651     else if (expecting == Expecting(ALPHA))
2652         {
2653         if (foundFirst == YES && foundEqual == NO)
2654             {
2655             /* We are filling in the probability for the constraint. Specifically, we expect exp(number). */
2656             if (IsSame ("Partial", tkn) == SAME)
2657                 {
2658                 for (i=0; i<numTaxa; i++)
2659                     tempSetNeg[i] = 0;
2660 
2661                 constraintType = PARTIAL;
2662                 expecting = Expecting(EQUALSIGN);
2663                 expecting |= Expecting(ALPHA);
2664                 }
2665             else if (IsSame ("Hard", tkn) == SAME)
2666                 {
2667                 constraintType = HARD;
2668                 expecting = Expecting(EQUALSIGN);
2669                 expecting |= Expecting(ALPHA);
2670                 }
2671             else if (IsSame ("Negative", tkn) == SAME)
2672                 {
2673                 constraintType = NEGATIVE;
2674                 expecting = Expecting(EQUALSIGN);
2675                 expecting |= Expecting(ALPHA);
2676                 }
2677             else if (IsSame ("Exp", tkn) == SAME || IsSame ("Exp", tkn) == CONSISTENT_WITH)
2678                 {
2679                 foundExp = YES;
2680                 foundDash = NO;
2681                 isNegative = NO;
2682                 expecting  = Expecting(LEFTPAR);
2683                 }
2684             else
2685                 {
2686                 MrBayesPrint ("%s   Do not understand %s\n", spacer, tkn);
2687                 return (ERROR);
2688                 }
2689             }
2690         else
2691             {
2692             /* We are defining a constraint in terms of a taxon set (called tkn, here) or we are referring to
2693                the taxon name. We should be able to find tkn in the list of taxon set names or in the list
2694                of taxon names. If we cannot, then we have a problem and return an error. */
2695             if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
2696                 {
2697                 if (numTaxaSets < 1)
2698                     {
2699                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
2700                     return (ERROR);
2701                     }
2702                 if (CheckString (taxaSetNames, numTaxaSets, tkn, &index) == ERROR)
2703                     {
2704                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
2705                     return (ERROR);
2706                     }
2707                 /* add taxa from taxset tkn to new tempSet */
2708                 for (i=0; i<numTaxa; i++)
2709                     {
2710                     if (IsBitSet(i, taxaSet[index]) == YES)
2711                         {
2712                         tempSetCurrent[i] = 1;
2713                         }
2714                     }
2715                 }
2716             else
2717                 {
2718                 tempSetCurrent[index] = 1;
2719                 }
2720             fromI = toJ = everyK = -1;
2721 
2722             expecting  = Expecting(ALPHA);
2723             expecting |= Expecting(NUMBER);
2724             if (constraintType != PARTIAL || foundColon == YES)
2725                 expecting |= Expecting(SEMICOLON);
2726             else
2727                 expecting |= Expecting(COLON);
2728             }
2729         }
2730     else if (expecting == Expecting(NUMBER))
2731         {
2732         if (foundFirst == YES && foundEqual == NO)
2733             {
2734             /* We are filling in the probability for the constraint. Specifically, we expect number. */
2735             sscanf (tkn, "%lf", &tempD);
2736             if (foundExp == NO && tempD < 0.0)
2737                 {
2738                 MrBayesPrint ("%s   The probability of a clade cannot be less than zero\n", spacer, tkn);
2739                 return (ERROR);
2740                 }
2741             if (isNegative == YES || foundDash == YES)
2742                 tempD *= -1.0;
2743             if (foundExp == YES)
2744                 {
2745                 expecting  = Expecting(RIGHTPAR);
2746                 }
2747             else
2748                 {
2749                 expecting  = Expecting(EQUALSIGN);
2750                 }
2751             foundFirst = NO;
2752             foundDash = NO;
2753             }
2754         else
2755             {
2756             if (strlen(tkn) == 1 && !strcmp(tkn, "."))
2757                 {
2758                 tempInt = numTaxa;
2759                 }
2760             else
2761                 {
2762                 sscanf (tkn, "%d", &tempInt);
2763                 if (tempInt <= 0 || tempInt > numTaxa)
2764                     {
2765                     MrBayesPrint ("%s   Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa);
2766                     return (ERROR);
2767                     }
2768                 }
2769             tempInt--;
2770             if (foundDash == YES)
2771                 {
2772                 if (fromI >= 0)
2773                     toJ = tempInt;
2774                 else
2775                     {
2776                     MrBayesPrint ("%s   Improperly formatted constraint\n", spacer);
2777                     return (ERROR);
2778                     }
2779                 foundDash = NO;
2780                 }
2781             else if (foundSlash == YES)
2782                 {
2783                 tempInt++;
2784                 if (tempInt <= 1)
2785                     {
2786                     MrBayesPrint ("%s   Improperly formatted constraint\n", spacer);
2787                     return (ERROR);
2788                     }
2789                 if (fromI >= 0 && toJ >= 0 && fromI < toJ)
2790                     everyK = tempInt;
2791                 else
2792                     {
2793                     MrBayesPrint ("%s   Improperly formatted constraint\n", spacer);
2794                     return (ERROR);
2795                     }
2796                 foundSlash = NO;
2797                 }
2798             else
2799                 {
2800                 if (fromI >= 0 && toJ < 0)
2801                     {
2802                     if (AddToGivenSet (fromI, toJ, everyK, 1, tempSetCurrent) == ERROR)
2803                         return (ERROR);
2804                     fromI = tempInt;
2805                     }
2806                 else if (fromI < 0 && toJ < 0)
2807                     {
2808                     fromI = tempInt;
2809                     }
2810                 else if (fromI >= 0 && toJ >= 0 && everyK < 0)
2811                     {
2812                     if (AddToGivenSet (fromI, toJ, everyK, 1, tempSetCurrent) == ERROR)
2813                         return (ERROR);
2814                     fromI = tempInt;
2815                     toJ = everyK = -1;
2816                     }
2817                 else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
2818                     {
2819                     if (AddToGivenSet (fromI, toJ, everyK, 1, tempSetCurrent) == ERROR)
2820                         return (ERROR);
2821                     fromI = tempInt;
2822                     toJ = everyK = -1;
2823                     }
2824                 else
2825                     {
2826                     MrBayesPrint ("%s   Improperly formatted constraint\n", spacer);
2827                         {
2828                         return (ERROR);
2829                         }
2830                     }
2831                 }
2832 
2833             expecting  = Expecting(ALPHA);
2834             expecting |= Expecting(NUMBER);
2835             expecting |= Expecting(DASH);
2836             expecting |= Expecting(BACKSLASH);
2837             if (constraintType != PARTIAL || foundColon == YES)
2838                 expecting |= Expecting(SEMICOLON);
2839             else
2840                 expecting |= Expecting(COLON);
2841             }
2842         }
2843     else if (expecting == Expecting(BACKSLASH))
2844         {
2845         foundSlash = YES;
2846         expecting = Expecting(NUMBER);
2847         }
2848     else if (expecting == Expecting(COLON))
2849         {
2850         if (foundColon == YES)
2851             {
2852             MrBayesPrint ("%s   Improperly formatted constraint: two colon characters in constraint command.\n", spacer);
2853             return (ERROR);
2854             }
2855 
2856         /* add set to tempSet */
2857         if (fromI >= 0 && toJ < 0)
2858             {
2859             if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2860                 return (ERROR);
2861             }
2862         else if (fromI >= 0 && toJ >= 0 && everyK < 0)
2863             {
2864             if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2865                 return (ERROR);
2866             }
2867         else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
2868             {
2869             if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2870                 return (ERROR);
2871             }
2872         fromI = toJ = everyK = -1;
2873         foundDash = foundSlash = NO;
2874 
2875         foundColon = YES;
2876         tempSetCurrent = tempSetNeg;
2877         expecting  = Expecting(ALPHA);
2878         expecting |= Expecting(NUMBER);
2879         }
2880     else
2881         return (ERROR);
2882 
2883     return (NO_ERROR);
2884 }
2885 
2886 
DoCtype(void)2887 int DoCtype (void)
2888 {
2889     int         i, foundIllegal, marks[5], numAppliedTo;
2890 
2891     /* add set to tempSet */
2892     if (fromI >= 0 && toJ < 0)
2893         {
2894         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2895             return (ERROR);
2896         }
2897     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
2898         {
2899         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2900             return (ERROR);
2901         }
2902     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
2903         {
2904         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2905             return (ERROR);
2906         }
2907 
2908     /* merge tempSet with ctype */
2909     numAppliedTo = 0;
2910     for (i=0; i<5; i++)
2911         marks[i] = NO;
2912     for (i=0; i<numChar; i++)
2913         {
2914         if (tempSet[i] != 0)
2915             {
2916             foundIllegal = NO;
2917             if (charOrdering != UNORD)
2918                 {
2919                 if (charInfo[i].charType == DNA)
2920                     {
2921                     foundIllegal = YES;
2922                     if (marks[0] == NO)
2923                         MrBayesPrint ("%s   Ctype not applied to DNA states which must be unordered\n", spacer);
2924                     marks[0] = YES;
2925                     }
2926                 else if (charInfo[i].charType == RNA)
2927                     {
2928                     foundIllegal = YES;
2929                     if (marks[1] == NO)
2930                         MrBayesPrint ("%s   Ctype not applied to RNA states which must be unordered\n", spacer);
2931                     marks[1] = YES;
2932                     }
2933                 else if (charInfo[i].charType == PROTEIN)
2934                     {
2935                     foundIllegal = YES;
2936                     if (marks[2] == NO)
2937                         MrBayesPrint ("%s   Ctype not applied to amino acid states which must be unordered\n", spacer);
2938                     marks[2] = YES;
2939                     }
2940                 else if (charInfo[i].charType == RESTRICTION)
2941                     {
2942                     foundIllegal = YES;
2943                     if (marks[3] == NO)
2944                         MrBayesPrint ("%s   Ctype not applied to restriction site states which must be unordered\n", spacer);
2945                     marks[3] = YES;
2946                     }
2947                 else if (charInfo[i].charType == CONTINUOUS)
2948                     {
2949                     foundIllegal = YES;
2950                     if (marks[4] == NO)
2951                         MrBayesPrint ("%s   Ctype not applied to continuous characters\n", spacer);
2952                     marks[4] = YES;
2953                     }
2954                 }
2955             if (foundIllegal == NO)
2956                 {
2957                 charInfo[i].ctype = charOrdering;
2958                 numAppliedTo++;
2959                 }
2960             }
2961         }
2962     if (numAppliedTo > 0)
2963         {
2964         MrBayesPrint ("%s   Ctype was applied to %d standard characters\n", spacer, numAppliedTo);
2965         }
2966     else
2967         {
2968         MrBayesPrint ("%s   No standard characters found to apply ctype to\n", spacer);
2969         }
2970 
2971 #   if 0
2972     for (i=0; i<numChar; i++)
2973         MrBayesPrint ("%4d -- %d\n", i, ctype[i]);
2974 #   endif
2975 
2976     return (NO_ERROR);
2977 }
2978 
2979 
DoCtypeParm(char * parmName,char * tkn)2980 int DoCtypeParm (char *parmName, char *tkn)
2981 {
2982     int     i, index, tempInt;
2983 
2984     if (defMatrix == NO)
2985         {
2986         MrBayesPrint ("%s   A matrix must be specified before typesets can be defined\n", spacer);
2987         return (ERROR);
2988         }
2989 
2990     if (expecting == Expecting(PARAMETER))
2991         {
2992         if (!strcmp(parmName, "Xxxxxxxxxx"))
2993             {
2994             if (IsSame ("Ordered", tkn) == SAME || IsSame ("Ordered", tkn) == CONSISTENT_WITH)
2995                 charOrdering = ORD;
2996             else if (IsSame ("Unordered", tkn) == SAME || IsSame ("Unordered", tkn) == CONSISTENT_WITH)
2997                 charOrdering = UNORD;
2998             else if (IsSame ("Dollo", tkn) == SAME || IsSame ("Dollo", tkn) == CONSISTENT_WITH)
2999                 charOrdering = DOLLO;
3000             else if (IsSame ("Irreversible", tkn) == SAME || IsSame ("Irreversible", tkn) == CONSISTENT_WITH)
3001                 charOrdering = IRREV;
3002             else
3003                 {
3004                 MrBayesPrint ("%s   Do not understand delimiter \"%s\"\n", spacer, tkn);
3005                 return (ERROR);
3006                 }
3007 
3008             /* clear tempSet */
3009             for (i=0; i<numChar; i++)
3010                 tempSet[i] = 0;
3011 
3012             fromI = toJ = everyK = -1;
3013             foundDash = foundSlash = NO;
3014             MrBayesPrint ("%s   Setting characters to %s\n", spacer, tkn);
3015             expecting = Expecting(COLON);
3016             }
3017         else
3018             return (ERROR);
3019         }
3020     else if (expecting == Expecting(COLON))
3021         {
3022         expecting  = Expecting(ALPHA) | Expecting(NUMBER);
3023         }
3024     else if (expecting == Expecting(ALPHA))
3025         {
3026         /* first, check that we are not trying to put in another character ordering */
3027         if (IsSame ("Ordered", tkn) == SAME || IsSame ("Ordered", tkn) == CONSISTENT_WITH)
3028             {
3029             MrBayesPrint ("%s   You cannot specify more than one ordering with a single use of ctype\n", spacer, tkn);
3030             return (ERROR);
3031             }
3032         else if (IsSame ("Unordered", tkn) == SAME || IsSame ("Unordered", tkn) == CONSISTENT_WITH)
3033             {
3034             MrBayesPrint ("%s   You cannot specify more than one ordering with a single use of ctype\n", spacer, tkn);
3035             return (ERROR);
3036             }
3037         else if (IsSame ("Dollo", tkn) == SAME || IsSame ("Dollo", tkn) == CONSISTENT_WITH)
3038             {
3039             MrBayesPrint ("%s   You cannot specify more than one ordering with a single use of ctype\n", spacer, tkn);
3040             return (ERROR);
3041             }
3042         else if (IsSame ("Irreversible", tkn) == SAME || IsSame ("Irreversible", tkn) == CONSISTENT_WITH)
3043             {
3044             MrBayesPrint ("%s   You cannot specify more than one ordering with a single use of ctype\n", spacer, tkn);
3045             return (ERROR);
3046             }
3047 
3048         /* We are defining a type set in terms of another (called tkn, here). We should be able
3049            to find tkn in the list of character set names. If we cannot, then we have a problem and
3050            return an error. */
3051         if (IsSame ("All", tkn) == SAME)
3052             {
3053             for (i=0; i<numChar; i++)
3054                 tempSet[i] = 1;
3055             fromI = toJ = everyK = -1;
3056             expecting = Expecting(SEMICOLON);
3057             }
3058         else
3059             {
3060             if (numCharSets < 1)
3061                 {
3062                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
3063                 return (ERROR);
3064                 }
3065             if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
3066                 {
3067                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
3068                 return (ERROR);
3069                 }
3070 
3071             /* add characters from charset tkn to new tempset */
3072             for (i=0; i<numChar; i++)
3073                 {
3074                 if (IsBitSet(i, charSet[index]) == YES)
3075                     tempSet[i] = 1;
3076                 }
3077             fromI = toJ = everyK = -1;
3078             expecting  = Expecting(ALPHA);
3079             expecting |= Expecting(NUMBER);
3080             expecting |= Expecting(SEMICOLON);
3081             }
3082         }
3083     else if (expecting == Expecting(NUMBER))
3084         {
3085         if (strlen(tkn) == 1 && tkn[0] == '.')
3086             tempInt = numChar;
3087         else
3088             sscanf (tkn, "%d", &tempInt);
3089         if (tempInt <= 0 || tempInt > numChar)
3090             {
3091             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
3092             return (ERROR);
3093             }
3094         tempInt--;
3095         if (foundDash == YES)
3096             {
3097             if (fromI >= 0)
3098                 toJ = tempInt;
3099             else
3100                 {
3101                 MrBayesPrint ("%s   Improperly formatted ctype\n", spacer);
3102                 return (ERROR);
3103                 }
3104             foundDash = NO;
3105             }
3106         else if (foundSlash == YES)
3107             {
3108             tempInt++;
3109             if (tempInt <= 1)
3110                 {
3111                 MrBayesPrint ("%s   Improperly formatted ctype\n", spacer);
3112                 return (ERROR);
3113                 }
3114             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
3115                 everyK = tempInt;
3116             else
3117                 {
3118                 MrBayesPrint ("%s   Improperly formatted ctype\n", spacer);
3119                 return (ERROR);
3120                 }
3121             foundSlash = NO;
3122             }
3123         else
3124             {
3125             if (fromI >= 0 && toJ < 0)
3126                 {
3127                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3128                     return (ERROR);
3129                 fromI = tempInt;
3130                 }
3131             else if (fromI < 0 && toJ < 0)
3132                 {
3133                 fromI = tempInt;
3134                 }
3135             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
3136                 {
3137                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3138                     return (ERROR);
3139                 fromI = tempInt;
3140                 toJ = everyK = -1;
3141                 }
3142             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
3143                 {
3144                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3145                     return (ERROR);
3146                 fromI = tempInt;
3147                 toJ = everyK = -1;
3148                 }
3149             else
3150                 {
3151                 MrBayesPrint ("%s   Improperly formatted ctype\n", spacer);
3152                     {
3153                     return (ERROR);
3154                     }
3155                 }
3156 
3157             }
3158 
3159         expecting  = Expecting(ALPHA);
3160         expecting |= Expecting(NUMBER);
3161         expecting |= Expecting(SEMICOLON);
3162         expecting |= Expecting(DASH);
3163         expecting |= Expecting(BACKSLASH);
3164         }
3165     else if (expecting == Expecting(DASH))
3166         {
3167         foundDash = YES;
3168         expecting = Expecting(NUMBER);
3169         }
3170     else if (expecting == Expecting(BACKSLASH))
3171         {
3172         foundSlash = YES;
3173         expecting = Expecting(NUMBER);
3174         }
3175     else
3176         return (ERROR);
3177 
3178     return (NO_ERROR);
3179 }
3180 
3181 
DoDelete(void)3182 int DoDelete (void)
3183 {
3184     int         i, alreadyDone;
3185 
3186     MrBayesPrint ("%s   Excluding taxa\n", spacer);
3187 
3188     /* add set to tempSet */
3189     if (fromI >= 0 && toJ < 0)
3190         {
3191         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3192             return (ERROR);
3193         }
3194     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
3195         {
3196         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3197             return (ERROR);
3198         }
3199     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
3200         {
3201         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3202             return (ERROR);
3203         }
3204 
3205     /* merge tempSet with taxaset */
3206     alreadyDone = NO;
3207     for (i=0; i<numTaxa; i++)
3208         {
3209         if (tempSet[i] == 1)
3210             {
3211             if (taxaInfo[i].isDeleted == YES && alreadyDone == NO)
3212                 {
3213                 MrBayesPrint ("%s   Some taxa already excluded\n", spacer);
3214                 alreadyDone = YES;
3215                 }
3216             taxaInfo[i].isDeleted = YES;
3217             }
3218         }
3219 
3220     SetLocalTaxa ();
3221     if (SetUpAnalysis(&globalSeed) == ERROR)
3222         return ERROR;
3223 
3224     /* show tempSet (for debugging) */
3225 #   if 0
3226     for (i=0; i<numTaxa; i++)
3227         MrBayesPrint ("%4d  %4d\n", i+1, tempSet[i]);
3228 #   endif
3229 
3230     return (NO_ERROR);
3231 }
3232 
3233 
DoDeleteParm(char * parmName,char * tkn)3234 int DoDeleteParm (char *parmName, char *tkn)
3235 {
3236     int     i, index, tempInt;
3237 
3238     if (defMatrix == NO)
3239         {
3240         MrBayesPrint ("%s   A matrix must be specified before you can delete taxa\n", spacer);
3241         return (ERROR);
3242         }
3243 
3244     if (foundFirst == NO)
3245         {
3246         /* this is the first time in */
3247         fromI = toJ = everyK = -1;
3248         foundDash = NO;
3249         for (i=0; i<numTaxa; i++) /* clear tempSet */
3250             tempSet[i] = 0;
3251         foundFirst = YES;
3252         }
3253 
3254     if (expecting == Expecting(ALPHA))
3255         {
3256         if (IsSame ("All", tkn) == SAME || IsSame ("All", tkn) == CONSISTENT_WITH)
3257             {
3258             for (i=0; i<numTaxa; i++)
3259                 tempSet[i] = 1;
3260             }
3261         else
3262             {
3263             if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
3264                 {
3265                 /* we are using a pre-defined taxa set */
3266                 if (numTaxaSets < 1)
3267                     {
3268                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
3269                     return (ERROR);
3270                     }
3271                 if (CheckString (taxaSetNames, numTaxaSets, tkn, &index) == ERROR)
3272                     {
3273                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
3274                     return (ERROR);
3275                     }
3276                 /* add taxa from taxset tkn to new tempSet */
3277                 for (i=0; i<numTaxa; i++)
3278                     {
3279                     if (IsBitSet (i, taxaSet[index]) == YES)
3280                         tempSet[i] = 1;
3281                     }
3282                 }
3283             else
3284                 {
3285                 /* we found the taxon name */
3286                 if (fromI >= 0 && toJ < 0)
3287                     {
3288                     if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3289                         return (ERROR);
3290                     }
3291                 else if (fromI >= 0 && toJ >= 0)
3292                     {
3293                     if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3294                         return (ERROR);
3295                     }
3296 
3297                 tempSet[index] = 1;
3298                 }
3299             }
3300         foundDash = NO;
3301         fromI = toJ = everyK = -1;
3302 
3303         expecting  = Expecting(ALPHA);
3304         expecting |= Expecting(NUMBER);
3305         expecting |= Expecting(SEMICOLON);
3306         }
3307     else if (expecting == Expecting(NUMBER))
3308         {
3309         if (strlen(tkn) == 1 && !strcmp(tkn, "."))
3310             tempInt = numTaxa;
3311         else
3312             {
3313             sscanf (tkn, "%d", &tempInt);
3314             if (tempInt <= 0 || tempInt > numTaxa)
3315                 {
3316                 MrBayesPrint ("%s   Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa);
3317                 return (ERROR);
3318                 }
3319             }
3320         tempInt--;
3321         if (foundDash == YES)
3322             {
3323             if (fromI >= 0)
3324                 toJ = tempInt;
3325             else
3326                 {
3327                 MrBayesPrint ("%s   Improperly formatted delete set\n", spacer);
3328                 return (ERROR);
3329                 }
3330             foundDash = NO;
3331             }
3332         else
3333             {
3334             if (fromI >= 0 && toJ < 0)
3335                 {
3336                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3337                     return (ERROR);
3338                 fromI = tempInt;
3339                 }
3340             else if (fromI < 0 && toJ < 0)
3341                 {
3342                 fromI = tempInt;
3343                 }
3344             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
3345                 {
3346                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3347                     return (ERROR);
3348                 fromI = tempInt;
3349                 toJ = everyK = -1;
3350                 }
3351             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
3352                 {
3353                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3354                     return (ERROR);
3355                 fromI = tempInt;
3356                 toJ = everyK = -1;
3357                 }
3358             else
3359                 {
3360                 MrBayesPrint ("%s   Improperly formatted delete set\n", spacer);
3361                     {
3362                     return (ERROR);
3363                     }
3364                 }
3365             }
3366         expecting  = Expecting(ALPHA);
3367         expecting |= Expecting(NUMBER);
3368         expecting |= Expecting(SEMICOLON);
3369         expecting |= Expecting(DASH);
3370         }
3371     else if (expecting == Expecting(DASH))
3372         {
3373         foundDash = YES;
3374         expecting = Expecting(NUMBER);
3375         }
3376     else
3377         return (ERROR);
3378 
3379     return (NO_ERROR);
3380 }
3381 
3382 
DoDimensions(void)3383 int DoDimensions (void)
3384 {
3385     if (inDataBlock == NO && inTaxaBlock == NO && inCharactersBlock == NO)
3386         {
3387         MrBayesPrint ("%s   Dimensions can only be defined in a data, characters or taxa block\n", spacer);
3388         return (ERROR);
3389         }
3390 
3391     /* other problems are detected already when reading in DoDimensionsParm */
3392     if (inDataBlock == YES && (defTaxa == NO || defChars == NO))
3393         {
3394         MrBayesPrint ("%s   Expecting both Ntax and Nchar to be defined in a data block\n", spacer);
3395         return (ERROR);
3396         }
3397 
3398     /* allocate matrix */
3399     if (inTaxaBlock == YES)
3400         {
3401         if (AllocTaxa () == ERROR)
3402             return ERROR;
3403         MrBayesPrint ("%s   Defining new set of %d taxa\n", spacer, numTaxa);
3404         }
3405 
3406     if (inCharactersBlock == YES)
3407         {
3408         if (AllocMatrix() == ERROR)
3409             return (ERROR);
3410         MrBayesPrint ("%s   Defining new character matrix with %d characters\n", spacer, numChar);
3411         }
3412 
3413     if (inDataBlock == YES)
3414         {
3415         if (AllocMatrix() == ERROR)
3416             return (ERROR);
3417         MrBayesPrint ("%s   Defining new matrix with %d taxa and %d characters\n", spacer, numTaxa, numChar);
3418         }
3419 
3420     return (NO_ERROR);
3421 }
3422 
3423 
DoDimensionsParm(char * parmName,char * tkn)3424 int DoDimensionsParm (char *parmName, char *tkn)
3425 {
3426     if (expecting == Expecting(PARAMETER))
3427         {
3428         expecting = Expecting(EQUALSIGN);
3429         }
3430     else
3431         {
3432         /* set Ntax (numTaxa) *****************************************************************/
3433         if (!strcmp(parmName, "Ntax"))
3434             {
3435             if (inCharactersBlock == YES)
3436                 {
3437                 MrBayesPrint ("%s   You cannot define ntax in a characters block\n");
3438                 return (ERROR);
3439                 }
3440             if (expecting == Expecting(EQUALSIGN))
3441                 expecting = Expecting(NUMBER);
3442             else if (expecting == Expecting(NUMBER))
3443                 {
3444                 sscanf (tkn, "%d", &numTaxa);
3445                 defTaxa = YES;
3446                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3447                 }
3448             else
3449                 return (ERROR);
3450             }
3451         /* set Nchar (numChar) ****************************************************************/
3452         else if (!strcmp(parmName, "Nchar"))
3453             {
3454             if (inTaxaBlock == YES)
3455                 {
3456                 MrBayesPrint ("%s   You cannot define nchar in a taxa block\n");
3457                 return (ERROR);
3458                 }
3459             if (expecting == Expecting(EQUALSIGN))
3460                 expecting = Expecting(NUMBER);
3461             else if (expecting == Expecting(NUMBER))
3462                 {
3463                 sscanf (tkn, "%d", &numChar);
3464                 defChars = YES;
3465                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3466                 }
3467             else
3468                 return (ERROR);
3469             }
3470         else
3471             return (ERROR);
3472         }
3473 
3474     return (NO_ERROR);
3475 }
3476 
3477 
DoDisclaimer(void)3478 int DoDisclaimer (void)
3479 {
3480     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
3481     MrBayesPrint ("   Disclaimer                                                                    \n");
3482     MrBayesPrint ("                                                                                 \n");
3483     MrBayesPrint ("   Copyright 2003 by John P. Huelsenbeck and Fredrik Ronquist                    \n");
3484     MrBayesPrint ("                                                                                 \n");
3485     MrBayesPrint ("   This software package is provided \"as is\" and without a warranty of any     \n");
3486     MrBayesPrint ("   kind. In no event shall the authors be held responsible for any damage        \n");
3487     MrBayesPrint ("   resulting from the use of this software. The program--including source code,  \n");
3488     MrBayesPrint ("   example data sets, and executables--is distributed free of charge for         \n");
3489     MrBayesPrint ("   academic use only.                                                            \n");
3490     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
3491 
3492     return (NO_ERROR);
3493 }
3494 
3495 
DoEndBlock(void)3496 int DoEndBlock (void)
3497 {
3498     if (inMrbayesBlock == YES)
3499         {
3500         MrBayesPrint ("   Exiting mrbayes block\n");
3501         inMrbayesBlock = NO;
3502         }
3503     else if (inDataBlock == YES)
3504         {
3505         MrBayesPrint ("   Exiting data block\n");
3506         inDataBlock = NO;
3507         }
3508     else if (inCharactersBlock == YES)
3509         {
3510         MrBayesPrint ("   Exiting characters block\n");
3511         inCharactersBlock = NO;
3512         }
3513     else if (inTaxaBlock == YES)
3514         {
3515         MrBayesPrint ("   Exiting taxa block\n");
3516         if (numNamedTaxa < numTaxa)
3517             {
3518             MrBayesPrint ("%s   Leaving taxa block without taxon labels being defined\n", spacer);
3519             FreeTaxa();
3520             }
3521         inTaxaBlock = NO;
3522         }
3523     else if (inTreesBlock == YES)
3524         {
3525         MrBayesPrint ("   Exiting trees block\n");
3526         inTreesBlock = NO;
3527         ResetTranslateTable();
3528         }
3529     else if (inForeignBlock == YES)
3530         {
3531         MrBayesPrint ("   Exiting foreign block\n");
3532         inForeignBlock = NO;
3533         }
3534     else
3535         {
3536         MrBayesPrint ("   Unknown \"end\" statement\n");
3537         return (ERROR);
3538         }
3539 
3540     strcpy(spacer,"");  /* reset indentation */
3541     return (NO_ERROR);
3542 }
3543 
3544 
DoExecute(void)3545 int DoExecute (void)
3546 {
3547     int         rc, cmdLine, lineTerm, longestLineLength, nErrors;
3548     char        *s, exeFileName[100];
3549     FILE        *fp;
3550     CmdType     *oldCommandPtr;
3551     char        *oldTokenP, oldToken[CMD_STRING_LENGTH];
3552 #   if defined (MPI_ENABLED)
3553     int         sumErrors;
3554 #   endif
3555 
3556     nErrors = 0;
3557     cmdLine = 0;
3558     numOpenExeFiles++;
3559     s = NULL;
3560     strncpy (exeFileName, inputFileName, 98);
3561 
3562     if (numOpenExeFiles > 1)
3563         MrBayesPrint ("\n%s   Executing file \"%s\"...\n\n", spacer, inputFileName);
3564     else
3565         MrBayesPrint ("%s   Executing file \"%s\"\n", spacer, inputFileName);
3566 
3567     /* Save old command ptr, token pointer and token */
3568     oldCommandPtr = commandPtr;
3569     oldTokenP     = tokenP;
3570     strcpy(oldToken, token);
3571 
3572     /* open binary file */
3573     if ((fp = OpenBinaryFileR(inputFileName)) == NULL)
3574         nErrors++;
3575 
3576     /* set indentation to 0 */
3577     strcpy (spacer, "");
3578 
3579 #   if defined (MPI_ENABLED)
3580     MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3581     if (sumErrors > 0)
3582         {
3583         MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3584         goto errorExit;
3585         }
3586 #   else
3587     if (nErrors > 0)
3588         goto errorExit;
3589 #   endif
3590 
3591     /* find out what type of line termination is used */
3592     lineTerm = LineTermType (fp);
3593     if (lineTerm == LINETERM_MAC)
3594         MrBayesPrint ("%s   Macintosh line termination\n", spacer);
3595     else if (lineTerm == LINETERM_DOS)
3596         MrBayesPrint ("%s   DOS line termination\n", spacer);
3597     else if (lineTerm == LINETERM_UNIX)
3598         MrBayesPrint ("%s   UNIX line termination\n", spacer);
3599     else
3600         {
3601         MrBayesPrint ("%s   Unknown line termination\n", spacer);
3602         nErrors++;
3603         }
3604 #   if defined (MPI_ENABLED)
3605     MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3606     if (sumErrors > 0)
3607         {
3608         MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3609         goto errorExit;
3610         }
3611 #   else
3612     if (nErrors > 0)
3613         goto errorExit;
3614 #   endif
3615 
3616     /* find length of longest line */
3617     longestLineLength = LongestLine (fp);
3618     MrBayesPrint ("%s   Longest line length = %d\n", spacer, longestLineLength);
3619     longestLineLength += 10;
3620 
3621     /* allocate a string long enough to hold a line */
3622     s = (char *)SafeMalloc((size_t)longestLineLength * sizeof(char));
3623     if (!s)
3624         {
3625         MrBayesPrint ("%s   Problem allocating string for reading file\n", spacer);
3626         nErrors++;
3627         }
3628 #   if defined (MPI_ENABLED)
3629     MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3630     if (sumErrors > 0)
3631         {
3632         MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3633         goto errorExit;
3634         }
3635 #   else
3636     if (nErrors > 0)
3637         goto errorExit;
3638 #   endif
3639 
3640     /* close binary file */
3641     SafeFclose (&fp);
3642 
3643     /* open text file */
3644     if ((fp = OpenTextFileR(inputFileName)) == NULL)
3645         {
3646         nErrors++;
3647         }
3648 #   if defined (MPI_ENABLED)
3649     MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3650     if (sumErrors > 0)
3651         {
3652         MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3653         goto errorExit;
3654         }
3655 #   else
3656     if (nErrors > 0)
3657         goto errorExit;
3658 #   endif
3659 
3660     /* parse file, reading each line in turn */
3661     MrBayesPrint ("%s   Parsing file\n", spacer);
3662 
3663     inMrbayesBlock = inDataBlock = inForeignBlock = inTreesBlock = NO;
3664     foundNewLine = NO;
3665     expecting = Expecting(COMMAND);
3666     cmdLine = 0;
3667 
3668     /* read lines into s until end of file */
3669     while ( fgets(s, longestLineLength, fp) != NULL)
3670         {
3671         foundNewLine = YES;
3672         cmdLine++;
3673 
3674         /* process string if not empty */
3675         if (strlen(s) > 1)
3676             {
3677             /* check that all characters in the string are valid */
3678             if (CheckStringValidity (s) == ERROR)
3679                 {
3680                 nErrors++;
3681                 }
3682 #           if defined (MPI_ENABLED)
3683             MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3684             if (sumErrors > 0)
3685                 {
3686                 MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3687                 goto errorExit;
3688                 }
3689 #           else
3690             if (nErrors > 0)
3691                 goto errorExit;
3692 #           endif
3693 
3694             /* interpret commands on line */
3695             rc = ParseCommand (s);
3696             if (rc == ERROR)
3697                 nErrors++;
3698 #           if defined (MPI_ENABLED)
3699             MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3700             if (sumErrors > 0)
3701                 {
3702                 MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3703                 goto errorExit;
3704                 }
3705 #           else
3706             if (nErrors > 0)
3707                 goto errorExit;
3708 #           endif
3709             if (rc == NO_ERROR_QUIT)
3710                 nErrors++;
3711 #           if defined (MPI_ENABLED)
3712             MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3713             if (sumErrors > 0)
3714                 goto quitExit;
3715 #           else
3716             if (nErrors > 0)
3717                 goto quitExit;
3718 #           endif
3719             }
3720         }
3721 
3722     MrBayesPrint ("%s   Reached end of file\n", spacer);
3723 
3724     if (inComment == YES)
3725         nErrors++;
3726 
3727 #   if defined (MPI_ENABLED)
3728     MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3729     if (sumErrors > 0)
3730         {
3731         MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3732         goto errorExit;
3733         }
3734 #   else
3735     if (nErrors > 0)
3736         goto errorExit;
3737 #   endif
3738 
3739     if (s)
3740         free (s);
3741     SafeFclose (&fp);
3742     numOpenExeFiles--;
3743 
3744     if (numOpenExeFiles > 0)
3745         {
3746         inMrbayesBlock = YES;
3747         MrBayesPrint ("\n   Returning execution to calling file ...\n\n");
3748         strcpy (spacer, "   ");
3749         }
3750     else
3751         strcpy (spacer, "");
3752 
3753     commandPtr = oldCommandPtr;
3754 
3755     return (NO_ERROR);
3756 
3757     quitExit:
3758         if (s)
3759             free (s);
3760         SafeFclose (&fp);
3761         numOpenExeFiles--;
3762         if (numOpenExeFiles > 0)
3763             {
3764             inMrbayesBlock = YES;
3765             strcpy (spacer, "   ");
3766             }
3767         else
3768             strcpy (spacer, "");
3769 
3770         commandPtr = oldCommandPtr;
3771         tokenP     = oldTokenP;
3772         strcpy(token, oldToken);
3773 
3774         return (NO_ERROR_QUIT);
3775 
3776     errorExit:
3777         if (inComment == YES)
3778             {
3779             MrBayesPrint ("%s   ERROR: Reached end of file while in comment.\n", spacer);
3780             inComment = NO;
3781             numComments = 0;
3782             }
3783         if (fp)
3784             {
3785             MrBayesPrint ("%s   The error occurred when reading char. %d-%d on line %d\n", spacer,
3786                 (size_t)(tokenP-s)-strlen(token)+1, (size_t)(tokenP-s), cmdLine);
3787             MrBayesPrint ("%s      in the file '%s'\n", spacer, exeFileName);
3788             }
3789         if (s)
3790             free (s);
3791         SafeFclose (&fp);
3792 
3793         /* make sure we exit the block we were reading from correctly */
3794         if (inMrbayesBlock == YES)
3795             inMrbayesBlock = NO;
3796         else if (inDataBlock == YES)
3797             inDataBlock = NO;
3798         else if (inTreesBlock == YES)
3799             {
3800             inTreesBlock = NO;
3801             ResetTranslateTable();
3802             }
3803         else if (inForeignBlock == YES)
3804             inForeignBlock = NO;
3805 
3806         /* make sure correct return if we came from mrbayes block in another execute file */
3807         if (numOpenExeFiles > 1)
3808             {
3809             inMrbayesBlock = YES;
3810             MrBayesPrint ("\n   Returning execution to calling file ...\n\n");
3811             strcpy (spacer, "   ");
3812             }
3813         else
3814             {
3815             strcpy (spacer, "");
3816             MrBayesPrint ("\n   Returning execution to command line ...\n\n");
3817             }
3818 
3819         numOpenExeFiles--;  /* we increase the value above even if no file is successfully opened */
3820 
3821         /* restore state of globals */
3822         commandPtr = oldCommandPtr;
3823         tokenP = oldTokenP;
3824         strcpy(token, oldToken);
3825 
3826         return (ERROR);
3827 }
3828 
3829 
DoExecuteParm(char * parmName,char * tkn)3830 int DoExecuteParm (char *parmName, char *tkn)
3831 {
3832     if (strlen(tkn)>99)
3833         {
3834         MrBayesPrint ("%s   Maximum allowed length of file name is 99 characters. The given name:\n", spacer);
3835         MrBayesPrint ("%s      '%s'\n", spacer,tkn);
3836         MrBayesPrint ("%s   has %d characters.\n", spacer,strlen(tkn));
3837         return (ERROR);
3838         }
3839     strcpy (inputFileName, tkn);
3840 
3841     expecting = Expecting (SEMICOLON);
3842 
3843     return (NO_ERROR);
3844 }
3845 
3846 
DoExclude(void)3847 int DoExclude (void)
3848 {
3849     int         i, alreadyDone;
3850 
3851     MrBayesPrint ("%s   Excluding character(s)\n", spacer);
3852 
3853     /* add set to tempSet */
3854     if (fromI >= 0 && toJ < 0)
3855         {
3856         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3857             return (ERROR);
3858         }
3859     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
3860         {
3861         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3862             return (ERROR);
3863         }
3864     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
3865         {
3866         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3867             return (ERROR);
3868         }
3869 
3870     /* merge tempSet with charset */
3871     alreadyDone = NO;
3872     for (i=0; i<numChar; i++)
3873         {
3874         if (tempSet[i] == 1)
3875             {
3876             if (charInfo[i].isExcluded == YES && alreadyDone == NO)
3877                 {
3878                 MrBayesPrint ("%s   Some characters already excluded\n", spacer);
3879                 alreadyDone = YES;
3880                 }
3881             charInfo[i].isExcluded = YES;
3882             }
3883         }
3884 
3885     foundFirst = NO;
3886 
3887     /* reset analysis to recompress data */
3888     if (SetUpAnalysis(&globalSeed) == ERROR)
3889         return ERROR;
3890 
3891     return (NO_ERROR);
3892 }
3893 
3894 
DoExcludeParm(char * parmName,char * tkn)3895 int DoExcludeParm (char *parmName, char *tkn)
3896 {
3897     int     i, index, tempInt;
3898 
3899     if (defMatrix == NO)
3900         {
3901         MrBayesPrint ("%s   A matrix must be specified before you can exclude characters\n", spacer);
3902         return (ERROR);
3903         }
3904 
3905     if (foundFirst == NO)
3906         {
3907         /* this is the first time in */
3908         fromI = toJ = everyK = -1;
3909         foundDash = foundSlash = NO;
3910         for (i=0; i<numChar; i++) /* clear tempSet */
3911             tempSet[i] = 0;
3912         foundFirst = YES;
3913         }
3914 
3915     if (expecting == Expecting(ALPHA))
3916         {
3917         if (IsSame ("All", tkn) == SAME || IsSame ("All", tkn) == CONSISTENT_WITH)
3918             {
3919             for (i=0; i<numChar; i++)
3920                 tempSet[i] = 1;
3921             }
3922         else if (IsSame ("Missambig", tkn) == SAME || IsSame ("Missambig", tkn) == CONSISTENT_WITH)
3923             {
3924             for (i=0; i<numChar; i++)
3925                 {
3926                 if (charInfo[i].isMissAmbig == YES)
3927                     tempSet[i] = 1;
3928                 }
3929             }
3930         else
3931             {
3932             /* we are using a pre-defined character set */
3933             if (numCharSets < 1)
3934                 {
3935                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
3936                 return (ERROR);
3937                 }
3938             if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
3939                 {
3940                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
3941                 return (ERROR);
3942                 }
3943             /* add characters from charset tkn to new tempSet */
3944             for (i=0; i<numChar; i++)
3945                 {
3946                 if (IsBitSet(i, charSet[index]) == YES)
3947                     tempSet[i] = 1;
3948                 }
3949             fromI = toJ = everyK = -1;
3950             }
3951 
3952         expecting  = Expecting(ALPHA);
3953         expecting |= Expecting(NUMBER);
3954         expecting |= Expecting(SEMICOLON);
3955         }
3956     else if (expecting == Expecting(NUMBER))
3957         {
3958         if (strlen(tkn) == 1 && tkn[0] == '.')
3959             tempInt = numChar;
3960         else
3961             sscanf (tkn, "%d", &tempInt);
3962         if (tempInt <= 0 || tempInt > numChar)
3963             {
3964             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
3965             return (ERROR);
3966             }
3967         tempInt--;
3968         if (foundDash == YES)
3969             {
3970             if (fromI >= 0)
3971                 toJ = tempInt;
3972             else
3973                 {
3974                 MrBayesPrint ("%s   Improperly formatted exclude set\n", spacer);
3975                 return (ERROR);
3976                 }
3977             foundDash = NO;
3978             }
3979         else if (foundSlash == YES)
3980             {
3981             tempInt++;
3982             if (tempInt <= 1)
3983                 {
3984                 MrBayesPrint ("%s   Improperly formatted exclude set\n", spacer);
3985                 return (ERROR);
3986                 }
3987             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
3988                 everyK = tempInt;
3989             else
3990                 {
3991                 MrBayesPrint ("%s   Improperly formatted exclude set\n", spacer);
3992                 return (ERROR);
3993                 }
3994             foundSlash = NO;
3995             }
3996         else
3997             {
3998             if (fromI >= 0 && toJ < 0)
3999                 {
4000                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4001                     return (ERROR);
4002                 fromI = tempInt;
4003                 }
4004             else if (fromI < 0 && toJ < 0)
4005                 {
4006                 fromI = tempInt;
4007                 }
4008             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4009                 {
4010                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4011                     return (ERROR);
4012                 fromI = tempInt;
4013                 toJ = everyK = -1;
4014                 }
4015             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4016                 {
4017                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4018                     return (ERROR);
4019                 fromI = tempInt;
4020                 toJ = everyK = -1;
4021                 }
4022             else
4023                 {
4024                 MrBayesPrint ("%s   Improperly formatted exclude set\n", spacer);
4025                     {
4026                     return (ERROR);
4027                     }
4028                 }
4029             }
4030         expecting  = Expecting(ALPHA);
4031         expecting |= Expecting(NUMBER);
4032         expecting |= Expecting(SEMICOLON);
4033         expecting |= Expecting(DASH);
4034         expecting |= Expecting(BACKSLASH);
4035         }
4036     else if (expecting == Expecting(DASH))
4037         {
4038         foundDash = YES;
4039         expecting = Expecting(NUMBER);
4040         }
4041     else if (expecting == Expecting(BACKSLASH))
4042         {
4043         foundSlash = YES;
4044         expecting = Expecting(NUMBER);
4045         }
4046     else
4047         return (ERROR);
4048 
4049     return (NO_ERROR);
4050 }
4051 
4052 
DoFormat(void)4053 int DoFormat (void)
4054 {
4055     if (inDataBlock == NO && inCharactersBlock == NO)
4056         {
4057         MrBayesPrint ("%s   Formats can only be defined in a data or characters block\n", spacer);
4058         return (ERROR);
4059         }
4060 
4061     return CheckInitialPartitions();
4062 }
4063 
4064 
DoFormatParm(char * parmName,char * tkn)4065 int DoFormatParm (char *parmName, char *tkn)
4066 {
4067     int         i, tempInt;
4068     char        tempStr[100];
4069 
4070     if (inDataBlock == NO && inCharactersBlock == NO)
4071         {
4072         MrBayesPrint ("%s   Formats can only be defined in a data or characters block\n", spacer);
4073         return (ERROR);
4074         }
4075     if (defTaxa == NO || defChars == NO)
4076         {
4077         MrBayesPrint ("%s   The dimensions of the matrix must be defined before the format\n", spacer);
4078         return (ERROR);
4079         }
4080 
4081     if (expecting == Expecting(PARAMETER))
4082         {
4083         expecting = Expecting(EQUALSIGN);
4084         if (!strcmp(parmName, "Interleave"))
4085             {
4086             expecting = Expecting(EQUALSIGN) | Expecting(PARAMETER) | Expecting(SEMICOLON);
4087             isInterleaved = YES;
4088             }
4089         }
4090     else
4091         {
4092         /* set Datatype (dataType) ************************************************************/
4093         if (!strcmp(parmName, "Datatype"))
4094             {
4095             if (expecting == Expecting(EQUALSIGN))
4096                 expecting = Expecting(ALPHA);
4097             else if (expecting == Expecting(ALPHA))
4098                 {
4099                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
4100                     {
4101                     if (isMixed == NO)
4102                         {
4103                         if (!strcmp(tempStr, "Dna"))
4104                             dataType = DNA;
4105                         else if (!strcmp(tempStr, "Rna"))
4106                             dataType = RNA;
4107                         else if (!strcmp(tempStr, "Protein"))
4108                             dataType = PROTEIN;
4109                         else if (!strcmp(tempStr, "Restriction"))
4110                             dataType = RESTRICTION;
4111                         else if (!strcmp(tempStr, "Standard"))
4112                             dataType = STANDARD;
4113                         else if (!strcmp(tempStr, "Continuous"))
4114                             dataType = CONTINUOUS;
4115                         else if (!strcmp(tempStr, "Mixed"))
4116                             {
4117                             dataType = MIXED;
4118                             isMixed = YES;
4119                             for (i=0; i<numChar; i++)
4120                                 tempSet[i] = 0;
4121                             fromI = toJ = everyK = -1;
4122                             foundDash = foundSlash = NO;
4123                             numDivisions = 0;
4124                             MrBayesPrint ("%s   Data is Mixed\n", spacer);
4125                             }
4126                         if (dataType == MIXED)
4127                             expecting = Expecting(LEFTPAR);
4128                         else
4129                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4130                         }
4131                     else
4132                         {
4133                         if (!strcmp(tempStr, "Dna"))
4134                             dataType = DNA;
4135                         else if (!strcmp(tempStr, "Rna"))
4136                             dataType = RNA;
4137                         else if (!strcmp(tempStr, "Protein"))
4138                             dataType = PROTEIN;
4139                         else if (!strcmp(tempStr, "Restriction"))
4140                             dataType = RESTRICTION;
4141                         else if (!strcmp(tempStr, "Standard"))
4142                             dataType = STANDARD;
4143                         else if (!strcmp(tempStr, "Continuous"))
4144                             dataType = CONTINUOUS;
4145                         else if (!strcmp(tempStr, "Mixed"))
4146                             {
4147                             MrBayesPrint ("%s   Cannot have mixed datatype within a mixed datatype\n", spacer);
4148                             return (ERROR);
4149                             }
4150                         expecting = Expecting(COLON);
4151                         for (i=0; i<numChar; i++)
4152                             tempSet[i] = 0;
4153                         fromI = toJ = everyK = -1;
4154                         foundDash = foundSlash = NO;
4155                         }
4156                     if (isMixed == NO)
4157                         {
4158                         numDivisions = 1;
4159                         for (i=0; i<numChar; i++)
4160                             {
4161                             charInfo[i].charType = dataType;
4162                             partitionId[i][0] = numDivisions;
4163                             }
4164                         }
4165                     }
4166                 else
4167                     {
4168                     MrBayesPrint ("%s   Invalid data type argument\n", spacer);
4169                     return (ERROR);
4170                     }
4171                 if (isMixed == NO)
4172                     MrBayesPrint ("%s   Data is %s\n", spacer, tempStr);
4173                 else if (strcmp(tempStr, "Mixed"))
4174                     MrBayesPrint ("%s      Data for partition %d is %s\n", spacer, numDivisions+1, tempStr);
4175                 }
4176             else if (expecting == Expecting(LEFTPAR))
4177                 {
4178                 expecting = Expecting(ALPHA);
4179                 }
4180             else if (expecting == Expecting(COLON))
4181                 {
4182                 expecting = Expecting(NUMBER);
4183                 }
4184             else if (expecting == Expecting(NUMBER))
4185                 {
4186                 if (strlen(tkn) == 1 && tkn[0] == '.')
4187                     tempInt = numChar;
4188                 else
4189                     sscanf (tkn, "%d", &tempInt);
4190                 if (tempInt <= 0 || tempInt > numChar)
4191                     {
4192                     MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
4193                     return (ERROR);
4194                     }
4195                 tempInt--;
4196                 if (foundDash == YES)
4197                     {
4198                     if (fromI >= 0)
4199                         toJ = tempInt;
4200                     else
4201                         {
4202                         MrBayesPrint ("%s   Improperly formatted partition\n", spacer);
4203                         return (ERROR);
4204                         }
4205                     foundDash = NO;
4206                     }
4207                 else if (foundSlash == YES)
4208                     {
4209                     tempInt++;
4210                     if (tempInt <= 1)
4211                         {
4212                         MrBayesPrint ("%s   Improperly formatted partition\n", spacer);
4213                         return (ERROR);
4214                         }
4215                     if (fromI >= 0 && toJ >= 0 && fromI < toJ)
4216                         everyK = tempInt;
4217                     else
4218                         {
4219                         MrBayesPrint ("%s   Improperly formatted partition\n", spacer);
4220                         return (ERROR);
4221                         }
4222                     foundSlash = NO;
4223                     }
4224                 else
4225                     {
4226                     if (fromI >= 0 && toJ < 0)
4227                         {
4228                         if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4229                             return (ERROR);
4230                         fromI = tempInt;
4231                         }
4232                     else if (fromI < 0 && toJ < 0)
4233                         {
4234                         fromI = tempInt;
4235                         }
4236                     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4237                         {
4238                         if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4239                             return (ERROR);
4240                         fromI = tempInt;
4241                         toJ = everyK = -1;
4242                         }
4243                     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4244                         {
4245                         if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4246                             return (ERROR);
4247                         fromI = tempInt;
4248                         toJ = everyK = -1;
4249                         }
4250                     else
4251                         {
4252                         MrBayesPrint ("%s   Improperly formatted partition\n", spacer);
4253                             {
4254                             return (ERROR);
4255                             }
4256                         }
4257 
4258                     }
4259                 expecting  = Expecting(NUMBER);
4260                 expecting |= Expecting(DASH);
4261                 expecting |= Expecting(BACKSLASH);
4262                 expecting |= Expecting(COMMA);
4263                 expecting |= Expecting(RIGHTPAR);
4264                 }
4265             else if (expecting == Expecting(DASH))
4266                 {
4267                 foundDash = YES;
4268                 expecting = Expecting(NUMBER);
4269                 }
4270             else if (expecting == Expecting(BACKSLASH))
4271                 {
4272                 foundSlash = YES;
4273                 expecting = Expecting(NUMBER);
4274                 }
4275             else if (expecting == Expecting(COMMA))
4276                 {
4277                 /* add set to tempSet */
4278                 if (fromI >= 0 && toJ < 0)
4279                     {
4280                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4281                         return (ERROR);
4282                     }
4283                 else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4284                     {
4285                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4286                         return (ERROR);
4287                     }
4288                 else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4289                     {
4290                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4291                         return (ERROR);
4292                     }
4293                 for (i=0; i<numChar; i++)
4294                     {
4295                     if (tempSet[i] == numDivisions)
4296                         charInfo[i].charType = dataType;
4297                     }
4298 
4299                 /* merge tempSet */
4300                 for (i=0; i<numChar; i++)
4301                     {
4302                     if (tempSet[i] != 0)
4303                         {
4304                         if (partitionId[i][0] == 0)
4305                             {
4306                             charInfo[i].charType = dataType;
4307                             partitionId[i][0] = numDivisions + 1;
4308                             }
4309                         else
4310                             {
4311                             MrBayesPrint ("%s   Improperly formatted partition (same character found in multiple partitions)\n", spacer);
4312                             return (ERROR);
4313                             }
4314                         }
4315                     }
4316 
4317                 /* increment number of partitions */
4318                 numDivisions++;
4319                 expecting = Expecting(ALPHA);
4320                 }
4321             else if (expecting == Expecting(RIGHTPAR))
4322                 {
4323                 /* add set to tempSet */
4324                 if (fromI >= 0 && toJ < 0)
4325                     {
4326                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4327                         return (ERROR);
4328                     }
4329                 else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4330                     {
4331                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4332                         return (ERROR);
4333                     }
4334                 else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4335                     {
4336                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4337                         return (ERROR);
4338                     }
4339 
4340                 /* merge tempSet */
4341                 for (i=0; i<numChar; i++)
4342                     {
4343                     if (tempSet[i] != 0)
4344                         {
4345                         if (partitionId[i][0] == 0)
4346                             {
4347                             charInfo[i].charType = dataType;
4348                             partitionId[i][0] = numDivisions + 1;
4349                             }
4350                         else
4351                             {
4352                             MrBayesPrint ("%s   Improperly formatted partition (same character found in multiple partitions)\n", spacer);
4353                             return (ERROR);
4354                             }
4355                         }
4356                     }
4357 
4358                 /* increment number of partitions */
4359                 numDivisions++;
4360                 if (isMixed == YES)
4361                     dataType = MIXED;
4362 
4363                 if (numDivisions > 1)
4364                     MrBayesPrint ("%s   There are a total of %d default data divisions\n", spacer, numDivisions);
4365                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4366                 }
4367             else
4368                 return (ERROR);
4369             }
4370         /* set Interleave (isInterleaved) *****************************************************/
4371         else if (!strcmp(parmName, "Interleave"))
4372             {
4373             if (expecting == Expecting(EQUALSIGN))
4374                 expecting = Expecting(ALPHA);
4375             else if (expecting == Expecting(ALPHA))
4376                 {
4377                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
4378                     {
4379                     if (!strcmp(tempStr, "Yes"))
4380                         isInterleaved = YES;
4381                     else
4382                         isInterleaved = NO;
4383                     }
4384                 else
4385                     {
4386                     MrBayesPrint ("%s   Invalid argument for interleaved data\n", spacer);
4387                     return (ERROR);
4388                     }
4389                 if (isInterleaved == YES)
4390                     MrBayesPrint ("%s   Data matrix is interleaved\n", spacer);
4391                 else
4392                     MrBayesPrint ("%s   Data matrix is not interleaved\n", spacer);
4393                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4394                 }
4395             else
4396                 return (ERROR);
4397             }
4398         /* set Gap (gapId) ********************************************************************/
4399         else if (!strcmp(parmName, "Gap"))
4400             {
4401             if (expecting == Expecting(EQUALSIGN))
4402                 {
4403                 expecting  = Expecting(ALPHA);
4404                 expecting |= Expecting(QUESTIONMARK);
4405                 expecting |= Expecting(DASH);
4406                 expecting |= Expecting(NUMBER);
4407                 expecting |= Expecting(ASTERISK);
4408                 expecting |= Expecting(EXCLAMATIONMARK);
4409                 expecting |= Expecting(PERCENT);
4410                 expecting |= Expecting(WEIRD);
4411                 expecting |= Expecting(VERTICALBAR);
4412                 }
4413             else if (((expecting & Expecting(ALPHA)) == Expecting(ALPHA)) ||
4414                      ((expecting & Expecting(QUESTIONMARK)) == Expecting(QUESTIONMARK)) ||
4415                      ((expecting & Expecting(DASH)) == Expecting(DASH)) ||
4416                      ((expecting & Expecting(NUMBER)) == Expecting(NUMBER)) ||
4417                      ((expecting & Expecting(ASTERISK)) == Expecting(ASTERISK)) ||
4418                      ((expecting & Expecting(EXCLAMATIONMARK)) == Expecting(EXCLAMATIONMARK)) ||
4419                      ((expecting & Expecting(PERCENT)) == Expecting(PERCENT)) ||
4420                      ((expecting & Expecting(WEIRD)) == Expecting(WEIRD)) ||
4421                      ((expecting & Expecting(VERTICALBAR)) == Expecting(VERTICALBAR)))
4422                 {
4423                 if (strlen(tkn) == 1)
4424                     {
4425                     if (tkn[0] == matchId || tkn[0] == missingId)
4426                         {
4427                         MrBayesPrint ("%s   Gap character matches matching or missing characters\n", spacer);
4428                         return (ERROR);
4429                         }
4430                     gapId = tkn[0];
4431                     }
4432                 else
4433                     {
4434                     MrBayesPrint ("%s   Invalid gap argument %s\n", spacer, tkn);
4435                     return (ERROR);
4436                     }
4437                 MrBayesPrint ("%s   Gaps coded as %s\n", spacer, tkn);
4438                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4439                 }
4440             else
4441                 return (ERROR);
4442             }
4443         /* set Missing (missingId) ************************************************************/
4444         else if (!strcmp(parmName, "Missing"))
4445             {
4446             if (expecting == Expecting(EQUALSIGN))
4447                 {
4448                 expecting  = Expecting(ALPHA);
4449                 expecting |= Expecting(QUESTIONMARK);
4450                 expecting |= Expecting(DASH);
4451                 expecting |= Expecting(NUMBER);
4452                 expecting |= Expecting(ASTERISK);
4453                 expecting |= Expecting(EXCLAMATIONMARK);
4454                 expecting |= Expecting(PERCENT);
4455                 expecting |= Expecting(WEIRD);
4456                 expecting |= Expecting(VERTICALBAR);
4457                 }
4458             else if (((expecting & Expecting(ALPHA)) == Expecting(ALPHA)) ||
4459                      ((expecting & Expecting(QUESTIONMARK)) == Expecting(QUESTIONMARK)) ||
4460                      ((expecting & Expecting(DASH)) == Expecting(DASH)) ||
4461                      ((expecting & Expecting(NUMBER)) == Expecting(NUMBER)) ||
4462                      ((expecting & Expecting(ASTERISK)) == Expecting(ASTERISK)) ||
4463                      ((expecting & Expecting(EXCLAMATIONMARK)) == Expecting(EXCLAMATIONMARK)) ||
4464                      ((expecting & Expecting(PERCENT)) == Expecting(PERCENT)) ||
4465                      ((expecting & Expecting(WEIRD)) == Expecting(WEIRD)) ||
4466                      ((expecting & Expecting(VERTICALBAR)) == Expecting(VERTICALBAR)))
4467                 {
4468                 if (strlen(tkn) == 1)
4469                     {
4470                     if (tkn[0] == gapId || tkn[0] == matchId)
4471                         {
4472                         MrBayesPrint ("%s   Missing character matches matching or gap characters\n", spacer);
4473                         return (ERROR);
4474                         }
4475                     missingId = tkn[0];
4476                     }
4477                 else
4478                     {
4479                     MrBayesPrint ("%s   Invalid missing argument %s\n", spacer, tkn);
4480                     return (ERROR);
4481                     }
4482                 MrBayesPrint ("%s   Missing data coded as %s\n", spacer, tkn);
4483                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4484                 }
4485             else
4486                 return (ERROR);
4487             }
4488         /* set Matchchar (matchId) ************************************************************/
4489         else if (!strcmp(parmName, "Matchchar"))
4490             {
4491             if (expecting == Expecting(EQUALSIGN))
4492                 {
4493                 expecting  = Expecting(ALPHA);
4494                 expecting |= Expecting(QUESTIONMARK);
4495                 expecting |= Expecting(DASH);
4496                 expecting |= Expecting(NUMBER);
4497                 expecting |= Expecting(ASTERISK);
4498                 expecting |= Expecting(EXCLAMATIONMARK);
4499                 expecting |= Expecting(PERCENT);
4500                 expecting |= Expecting(WEIRD);
4501                 expecting |= Expecting(VERTICALBAR);
4502                 }
4503             else if (((expecting & Expecting(ALPHA)) == Expecting(ALPHA)) ||
4504                      ((expecting & Expecting(QUESTIONMARK)) == Expecting(QUESTIONMARK)) ||
4505                      ((expecting & Expecting(DASH)) == Expecting(DASH)) ||
4506                      ((expecting & Expecting(NUMBER)) == Expecting(NUMBER)) ||
4507                      ((expecting & Expecting(ASTERISK)) == Expecting(ASTERISK)) ||
4508                      ((expecting & Expecting(EXCLAMATIONMARK)) == Expecting(EXCLAMATIONMARK)) ||
4509                      ((expecting & Expecting(PERCENT)) == Expecting(PERCENT)) ||
4510                      ((expecting & Expecting(WEIRD)) == Expecting(WEIRD)) ||
4511                      ((expecting & Expecting(VERTICALBAR)) == Expecting(VERTICALBAR)))
4512                 {
4513                 if (strlen(tkn) == 1)
4514                     {
4515                     if (tkn[0] == gapId || tkn[0] == missingId)
4516                         {
4517                         MrBayesPrint ("%s   Matching character matches gap or missing characters\n", spacer);
4518                         return (ERROR);
4519                         }
4520                     matchId = tkn[0];
4521                     }
4522                 else
4523                     {
4524                     MrBayesPrint ("%s   Invalid matchchar argument %s\n", spacer, tkn);
4525                     return (ERROR);
4526                     }
4527                 MrBayesPrint ("%s   Matching characters coded as %s\n", spacer, tkn);
4528                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4529                 }
4530             else
4531                 return (ERROR);
4532             }
4533         /* skip Symbols ***************************************************************/
4534         else if (!strcmp(parmName, "Symbols"))
4535             {
4536             if (expecting == Expecting(EQUALSIGN))
4537                 {
4538                 MrBayesPrint ("%s   WARNING: MrBayes does not support 'symbols' specification; default symbols assumed\n", spacer);
4539                 readWord=YES;
4540                 expecting = Expecting(ALPHA);
4541                 }
4542             else if (expecting == Expecting(ALPHA))
4543                 {
4544                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4545                 }
4546             else
4547                 return (ERROR);
4548             }
4549         /* on Equate return ERROR ***************************************************************/
4550         else if (!strcmp(parmName, "Equate"))
4551             {
4552             MrBayesPrint ("%s   ERROR: MrBayes does not support 'Equate' macros; please remove or comment out\n", spacer);
4553             return (ERROR);
4554             }
4555         else
4556             return (ERROR);
4557         }
4558 
4559     return (NO_ERROR);
4560 }
4561 
4562 
DoHelp(void)4563 int DoHelp (void)
4564 {
4565     int         i, j, longestDescription;
4566     CmdType     *p;
4567 
4568     if (foundFirst == NO)
4569         {
4570         longestDescription = 0;
4571         for (i=1; i<NUMCOMMANDS; i++)
4572             {
4573             p = commands + i;
4574             if ((int)strlen(p->string) > longestDescription)
4575                 longestDescription = (int) strlen(p->string);
4576             }
4577 
4578         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
4579         MrBayesPrint ("   Commands that are available from the command                                  \n");
4580         MrBayesPrint ("   line or from a MrBayes block include:                                         \n");
4581         MrBayesPrint ("                                                                                 \n");
4582         for (i=1; i<NUMCOMMANDS; i++)
4583             {
4584             p = commands + i;
4585             if (p->cmdUse == IN_CMD && p->hiding == SHOW)
4586                 {
4587                 MrBayesPrint ("   %s", p->string);
4588                 for (j=0; j<longestDescription - (int) strlen(p->string); j++)
4589                 MrBayesPrint (" ");
4590                 MrBayesPrint (" -- %s\n", p->cmdDescription);
4591                 }
4592             }
4593         MrBayesPrint ("                                                                                 \n");
4594         MrBayesPrint ("   Commands that should be in a NEXUS file (data                                 \n");
4595         MrBayesPrint ("   block, trees block or taxa block) include:                                                \n");
4596         MrBayesPrint ("                                                                                 \n");
4597         for (i=1; i<NUMCOMMANDS; i++)
4598             {
4599             p = commands + i;
4600             if (p->cmdUse == IN_FILE && p->hiding == SHOW)
4601                 {
4602                 MrBayesPrint ("   %s", p->string);
4603                 for (j=0; j<longestDescription - (int) strlen(p->string); j++)
4604                 MrBayesPrint (" ");
4605                 MrBayesPrint (" -- %s\n", p->cmdDescription);
4606                 }
4607             }
4608         MrBayesPrint ("                                                                                 \n");
4609         MrBayesPrint ("   Note that this program supports the use of the shortest unambiguous           \n");
4610         MrBayesPrint ("   spelling of the above commands (e.g., \"exe\" instead of \"execute\").        \n");
4611         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
4612         }
4613     foundFirst = NO;
4614 
4615     return (NO_ERROR);
4616 }
4617 
4618 
DoHelpParm(char * parmName,char * tkn)4619 int DoHelpParm (char *parmName, char *tkn)
4620 {
4621     int         i, j, tkLen, targetLen, numDiff, numMatches;
4622     CmdType     *p, *q=NULL;
4623 
4624     if (expecting == Expecting(ALPHA))
4625         {
4626         p = commands + 0;
4627         tkLen = (int) strlen(tkn);
4628         numMatches = 0;
4629         for (i=0; i<NUMCOMMANDS; i++)
4630             {
4631             targetLen = (int) strlen(p->string);
4632             if (tkLen <= targetLen)
4633                 {
4634                 for (j=0, numDiff=0; j<tkLen; j++)
4635                     {
4636                     if (ChangeCase(tkn[j]) != ChangeCase(p->string[j]))
4637                         numDiff++;
4638                     }
4639                 if (numDiff == 0)
4640                     {
4641                     numMatches++;
4642                     q = p;
4643                     if (tkLen == targetLen)
4644                         break;
4645                     }
4646                 }
4647             p++;
4648             }
4649         if (numMatches == 0)
4650             {
4651             MrBayesPrint ("%s   Could not find command \"%s\"\n", spacer, tkn);
4652             return (ERROR);
4653             }
4654         else if (numMatches == 1)
4655             {
4656             if (GetUserHelp (q->string) == ERROR)
4657                 {
4658                 MrBayesPrint ("%s   Problem getting help for command \"%s\"\n", spacer, q->string);
4659                 }
4660             }
4661         else
4662             {
4663             MrBayesPrint ("%s   Ambiguous command \"%s\"\n", spacer, tkn);
4664             return (ERROR);
4665             }
4666 
4667         expecting = Expecting(SEMICOLON);
4668         foundFirst = YES;
4669         }
4670     else
4671         return (ERROR);
4672 
4673     return (NO_ERROR);
4674 }
4675 
4676 
DoInclude(void)4677 int DoInclude (void)
4678 {
4679     int         i, alreadyDone;
4680 
4681     MrBayesPrint ("%s   Including character(s)\n", spacer);
4682 
4683     /* add set to tempSet */
4684     if (fromI >= 0 && toJ < 0)
4685         {
4686         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4687             return (ERROR);
4688         }
4689     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4690         {
4691         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4692             return (ERROR);
4693         }
4694     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4695         {
4696         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4697             return (ERROR);
4698         }
4699 
4700     /* merge tempSet with excludedChars */
4701     alreadyDone = NO;
4702     for (i=0; i<numChar; i++)
4703         {
4704         if (tempSet[i] == 1)
4705             {
4706             if (charInfo[i].isExcluded == NO && alreadyDone == NO)
4707                 {
4708                 MrBayesPrint ("%s   Some characters already included\n", spacer);
4709                 alreadyDone = YES;
4710                 }
4711             charInfo[i].isExcluded = NO;
4712             }
4713         }
4714 
4715     /* reset analysis to recompress data */
4716     if (SetUpAnalysis(&globalSeed) == ERROR)
4717         return ERROR;
4718 
4719     return (NO_ERROR);
4720 }
4721 
4722 
DoIncludeParm(char * parmName,char * tkn)4723 int DoIncludeParm (char *parmName, char *tkn)
4724 {
4725     int     i, index, tempInt;
4726 
4727     if (defMatrix == NO)
4728         {
4729         MrBayesPrint ("%s   A matrix must be specified before you can include characters\n", spacer);
4730         return (ERROR);
4731         }
4732 
4733     if (foundFirst == NO)
4734         {
4735         /* this is the first time in */
4736         fromI = toJ = everyK = -1;
4737         foundDash = foundSlash = NO;
4738         for (i=0; i<numChar; i++) /* clear tempSet */
4739             tempSet[i] = 0;
4740         foundFirst = YES;
4741         }
4742 
4743     if (expecting == Expecting(ALPHA))
4744         {
4745         if (IsSame ("All", tkn) == SAME || IsSame ("All", tkn) == CONSISTENT_WITH)
4746             {
4747             for (i=0; i<numChar; i++)
4748                 tempSet[i] = 1;
4749             }
4750         else if (IsSame ("Missambig", tkn) == SAME || IsSame ("Missambig", tkn) == CONSISTENT_WITH)
4751             {
4752             for (i=0; i<numChar; i++)
4753                 {
4754                 if (charInfo[i].isMissAmbig == YES)
4755                     tempSet[i] = 1;
4756                 }
4757             }
4758         else
4759             {
4760             /* we are using a pre-defined character set */
4761             if (numCharSets < 1)
4762                 {
4763                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
4764                 return (ERROR);
4765                 }
4766             if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
4767                 {
4768                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
4769                 return (ERROR);
4770                 }
4771             /* add characters from charset tkn to new tempSet */
4772             for (i=0; i<numChar; i++)
4773                 {
4774                 if (IsBitSet(i, charSet[index]) == YES)
4775                     tempSet[i] = 1;
4776                 }
4777             fromI = toJ = everyK = -1;
4778             }
4779 
4780         expecting  = Expecting(ALPHA);
4781         expecting |= Expecting(NUMBER);
4782         expecting |= Expecting(SEMICOLON);
4783         }
4784     else if (expecting == Expecting(NUMBER))
4785         {
4786         if (strlen(tkn) == 1 && tkn[0] == '.')
4787             tempInt = numChar;
4788         else
4789             sscanf (tkn, "%d", &tempInt);
4790         if (tempInt <= 0 || tempInt > numChar)
4791             {
4792             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
4793             return (ERROR);
4794             }
4795         tempInt--;
4796         if (foundDash == YES)
4797             {
4798             if (fromI >= 0)
4799                 toJ = tempInt;
4800             else
4801                 {
4802                 MrBayesPrint ("%s   Improperly formatted include set\n", spacer);
4803                 return (ERROR);
4804                 }
4805             foundDash = NO;
4806             }
4807         else if (foundSlash == YES)
4808             {
4809             tempInt++;
4810             if (tempInt <= 1)
4811                 {
4812                 MrBayesPrint ("%s   Improperly formatted include set\n", spacer);
4813                 return (ERROR);
4814                 }
4815             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
4816                 everyK = tempInt;
4817             else
4818                 {
4819                 MrBayesPrint ("%s   Improperly formatted include set\n", spacer);
4820                 return (ERROR);
4821                 }
4822             foundSlash = NO;
4823             }
4824         else
4825             {
4826             if (fromI >= 0 && toJ < 0)
4827                 {
4828                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4829                     return (ERROR);
4830                 fromI = tempInt;
4831                 }
4832             else if (fromI < 0 && toJ < 0)
4833                 {
4834                 fromI = tempInt;
4835                 }
4836             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4837                 {
4838                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4839                     return (ERROR);
4840                 fromI = tempInt;
4841                 toJ = everyK = -1;
4842                 }
4843             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4844                 {
4845                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4846                     return (ERROR);
4847                 fromI = tempInt;
4848                 toJ = everyK = -1;
4849                 }
4850             else
4851                 {
4852                 MrBayesPrint ("%s   Improperly formatted include set\n", spacer);
4853                     {
4854                     return (ERROR);
4855                     }
4856                 }
4857             }
4858         expecting  = Expecting(ALPHA);
4859         expecting |= Expecting(NUMBER);
4860         expecting |= Expecting(SEMICOLON);
4861         expecting |= Expecting(DASH);
4862         expecting |= Expecting(BACKSLASH);
4863         }
4864     else if (expecting == Expecting(DASH))
4865         {
4866         foundDash = YES;
4867         expecting = Expecting(NUMBER);
4868         }
4869     else if (expecting == Expecting(BACKSLASH))
4870         {
4871         foundSlash = YES;
4872         expecting = Expecting(NUMBER);
4873         }
4874     else
4875         return (ERROR);
4876 
4877     return (NO_ERROR);
4878 }
4879 
4880 
DoLog(void)4881 int DoLog (void)
4882 {
4883     if (logToFile == YES)
4884         {
4885         SafeFclose (&logFileFp);
4886         if (replaceLogFile == YES)
4887             {
4888             if ((logFileFp = OpenTextFileW (logFileName)) == NULL)
4889                 {
4890                 logToFile = NO;
4891                 return (ERROR);
4892                 }
4893             }
4894         else
4895             {
4896             if ((logFileFp = OpenTextFileA (logFileName)) == NULL)
4897                 {
4898                 logToFile = NO;
4899                 return (ERROR);
4900                 }
4901             }
4902         MrBayesPrint ("%s   Logging screen output to file \"%s\"\n", spacer, logFileName);
4903         }
4904     else
4905         {
4906         SafeFclose (&logFileFp);
4907         MrBayesPrint ("%s   Terminating log output\n", spacer);
4908         }
4909 
4910     return (NO_ERROR);
4911 }
4912 
4913 
DoLogParm(char * parmName,char * tkn)4914 int DoLogParm (char *parmName, char *tkn)
4915 {
4916     if (expecting == Expecting(PARAMETER))
4917         {
4918         if (!strcmp(parmName, "Start"))
4919             {
4920             if (logToFile == YES)
4921                 MrBayesPrint ("%s   Logging to file is already on\n", spacer, logFileName);
4922             else
4923                 logToFile = YES;
4924             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4925             }
4926         else if (!strcmp(parmName, "Stop"))
4927             {
4928             if (logToFile == NO)
4929                 MrBayesPrint ("%s   Logging to file is already off\n", spacer, logFileName);
4930             else
4931                 logToFile = NO;
4932             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4933             }
4934         else if (!strcmp(parmName, "Replace"))
4935             {
4936             replaceLogFile = YES;
4937             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4938             }
4939         else if (!strcmp(parmName, "Append"))
4940             {
4941             replaceLogFile = NO;
4942             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4943             }
4944         else
4945             expecting = Expecting(EQUALSIGN);
4946         }
4947     else
4948         {
4949         if (!strcmp(parmName, "Filename"))
4950             {
4951             if (expecting == Expecting(EQUALSIGN))
4952                 {
4953                 expecting = Expecting(ALPHA);
4954                 readWord = YES;
4955                 }
4956             else if (expecting == Expecting(ALPHA))
4957                 {
4958                 strcpy (logFileName, tkn);
4959                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4960                 }
4961             else
4962                 return (ERROR);
4963             }
4964         else
4965             {
4966             MrBayesPrint ("%s   Unknown parameter in Log\n", spacer);
4967             return (ERROR);
4968             }
4969         }
4970 
4971     return (NO_ERROR);
4972 }
4973 
4974 
DoManual(void)4975 int DoManual (void)
4976 {
4977     int     i, j, logSetting;
4978     char    title[100];
4979     FILE    *fp, *logfp;
4980     CmdType *p;
4981 
4982     /* try to open file, return error if present */
4983     if ((fp = OpenTextFileRQuait(manFileName)) != NULL)
4984         {
4985         MrBayesPrint ("%s   File \"%s\" already exists \n", spacer, manFileName);
4986         SafeFclose(&fp);
4987         return (ERROR);
4988         }
4989 
4990     /* try to open file for writing, return error if not possible */
4991     if ((fp = OpenTextFileW(manFileName)) == NULL)
4992         return (ERROR);
4993 
4994     /* print message */
4995     MrBayesPrint ("%s   Producing command reference file \"%s\"\n", spacer, manFileName);
4996 
4997     /* temporarily disable normal logging and switch echoing off */
4998     logSetting = logToFile;
4999     logfp = logFileFp;
5000     echoMB = NO;
5001     logToFile = YES;
5002     logFileFp = fp;
5003 
5004     /* produce command reference file */
5005     /* header */
5006     strcpy (title, "Command Reference for MrBayes ver. ");
5007     strcat (title, VERSION_NUMBER);
5008 
5009     i = (70 - (int) strlen (title)) / 2;
5010     j = 70 - i - (int) strlen(title);
5011 
5012     MrBayesPrint ("                                                                                 \n");
5013     MrBayesPrint ("                                                                                 \n");
5014     MrBayesPrint ("                                                                                 \n");
5015     MrBayesPrint ("                                                                                 \n");
5016     MrBayesPrint ("      %*c%s%*c      \n", i, ' ', title, j, ' ');
5017     MrBayesPrint ("                                                                                 \n");
5018     MrBayesPrint ("                   (c) John P. Huelsenbeck, Fredrik Ronquist                     \n");
5019     MrBayesPrint ("                               and Maxim Teslenko                                \n");
5020     MrBayesPrint ("                                                                                 \n");
5021 
5022     /* summary */
5023     MrBayesPrint ("                                                                                 \n");
5024     MrBayesPrint ("   ***************************************************************************   \n");
5025     MrBayesPrint ("   *                                                                         *   \n");
5026     MrBayesPrint ("   *  1. Command summary                                                     *   \n");
5027     MrBayesPrint ("   *                                                                         *   \n");
5028     MrBayesPrint ("   ***************************************************************************   \n");
5029     MrBayesPrint ("                                                                                 \n");
5030     foundFirst = NO;
5031     if (DoHelp() == ERROR)
5032         {
5033         MrBayesPrint ("%s   Could not produce command reference summary\n", spacer);
5034         goto errorExit;
5035         }
5036 
5037     /* list of MrBayes commands */
5038     MrBayesPrint ("                                                                                 \n");
5039     MrBayesPrint ("   ***************************************************************************   \n");
5040     MrBayesPrint ("   *                                                                         *   \n");
5041     MrBayesPrint ("   *  2. MrBayes commands                                                    *   \n");
5042     MrBayesPrint ("   *                                                                         *   \n");
5043     MrBayesPrint ("   ***************************************************************************   \n");
5044     MrBayesPrint ("                                                                                 \n");
5045     for (i=1; i<NUMCOMMANDS; i++)
5046         {
5047         p = commands + i;
5048         if (p->cmdUse == IN_CMD && p->hiding == SHOW)
5049             {
5050             if (GetUserHelp(p->string)==ERROR)
5051                 goto errorExit;
5052             }
5053         }
5054 
5055     /* list of data or tree block commands */
5056     MrBayesPrint ("                                                                                 \n");
5057     MrBayesPrint ("   ***************************************************************************   \n");
5058     MrBayesPrint ("   *                                                                         *   \n");
5059     MrBayesPrint ("   *  3. 'Data' or 'tree' block commands (in #NEXUS file)                    *   \n");
5060     MrBayesPrint ("   *                                                                         *   \n");
5061     MrBayesPrint ("   ***************************************************************************   \n");
5062     MrBayesPrint ("                                                                                 \n");
5063     for (i=1; i<NUMCOMMANDS; i++)
5064         {
5065         p = commands + i;
5066         if (p->cmdUse == IN_FILE && p->hiding == SHOW)
5067             {
5068             if (GetUserHelp(p->string) == ERROR)
5069                 goto errorExit;
5070             }
5071         }
5072 
5073     /* return logging to previous setings and switch echoing on */
5074     SafeFclose (&fp);
5075     logToFile = logSetting;
5076     logFileFp = logfp;
5077     echoMB = YES;
5078 
5079     MrBayesPrint ("%s   Successfully produced command reference file \"%s\"\n", spacer, manFileName);
5080 
5081     return (NO_ERROR);
5082 
5083     errorExit:
5084         SafeFclose (&fp);
5085         logToFile = logSetting;
5086         logFileFp = logfp;
5087         echoMB = YES;
5088 
5089         return (ERROR);
5090 }
5091 
5092 
DoManualParm(char * parmName,char * tkn)5093 int DoManualParm (char *parmName, char *tkn)
5094 {
5095     if (expecting == Expecting(PARAMETER))
5096         {
5097         expecting = Expecting(EQUALSIGN);
5098         }
5099     else
5100         {
5101         if (!strcmp(parmName, "Filename"))
5102             {
5103             if (expecting == Expecting(EQUALSIGN))
5104                 {
5105                 expecting = Expecting(ALPHA);
5106                 readWord = YES;
5107                 }
5108             else if (expecting == Expecting(ALPHA))
5109                 {
5110                 strcpy (manFileName, tkn);
5111                 expecting = Expecting(SEMICOLON);
5112                 }
5113             else
5114                 return (ERROR);
5115             }
5116         else
5117             {
5118             MrBayesPrint ("%s   Unknown parameter in Manual\n", spacer);
5119             return (ERROR);
5120             }
5121         }
5122 
5123     return (NO_ERROR);
5124 }
5125 
5126 
DoMatrix(void)5127 int DoMatrix (void)
5128 {
5129     int         i, j, hasMissingAmbig;
5130 
5131     if (taxonCount != numTaxa)
5132         {
5133         MrBayesPrint ("%s   Problem with number of taxa read in (%d taxa read in, while expecting %d)\n", spacer, taxonCount, numTaxa);
5134         FreeMatrix();
5135         return (ERROR);
5136         }
5137     for (i=0; i<numTaxa; i++)
5138         {
5139         if (taxaInfo[i].charCount != numChar)
5140             {
5141             MrBayesPrint ("%s   Problem with number of characters read in (%d expected for taxon %d, %d read in)\n", spacer, numChar, i, taxaInfo[i].charCount);
5142             FreeMatrix();
5143             return (ERROR);
5144             }
5145         }
5146 
5147     /* find out which characters have missing or ambiguous states (one time only, so no special function) */
5148     for (i=0; i<numChar; i++)
5149         {
5150         hasMissingAmbig = NO;
5151         for (j=0; j<numTaxa; j++)
5152             {
5153             if (IsMissing (matrix[pos(j,i,numChar)], charInfo[i].charType) == YES)
5154                 hasMissingAmbig = YES;
5155             if (IsAmbig (matrix[pos(j,i,numChar)], charInfo[i].charType) == YES)
5156                 hasMissingAmbig = YES;
5157             }
5158         if (hasMissingAmbig == YES)
5159             charInfo[i].isMissAmbig = YES;
5160         }
5161 
5162     MrBayesPrint ("%s   Successfully read matrix\n", spacer);
5163     if (matrixHasPoly == YES)
5164         MrBayesPrint ("%s   Matrix contains polymorphisms, interpreted as ambiguity\n", spacer);
5165     defMatrix = YES;
5166     isTaxsetDef = YES;
5167 
5168     /* add name of default partition */
5169     if (AddString (&partitionNames, 0, "Default") == ERROR)
5170         {
5171         MrBayesPrint ("%s   Problem adding Default name to partition list\n", spacer);
5172         return (ERROR);
5173         }
5174     numDefinedPartitions = 1;
5175 
5176     if (numDefinedSpeciespartitions == 0)   /* the default species partition could have been added already in DoTaxLabels */
5177         {
5178         /* add default speciespartition name to list of valid speciespartitions */
5179         if (AddString (&speciespartitionNames, 0, "Default") == ERROR)
5180             {
5181             MrBayesPrint ("%s   Problem adding Default speciespartition to list\n", spacer);
5182             return (ERROR);
5183             }
5184 
5185         /* add default species name set */
5186         AddNameSet(&speciesNameSets, 0, taxaNames, numTaxa);
5187 
5188         /* set number of defined speciespartitions to 1 */
5189         numDefinedSpeciespartitions = 1;
5190         }
5191 
5192     if (SetPartition (0) == ERROR)
5193         return ERROR;
5194 
5195     if (SetSpeciespartition (0) == ERROR)
5196         return ERROR;
5197 
5198     if (numCurrentDivisions == 1)
5199         MrBayesPrint ("%s   Setting default partition (does not divide up characters)\n", spacer);
5200     else
5201         MrBayesPrint ("%s   Setting default partition, dividing characters into %d parts\n", spacer, numCurrentDivisions);
5202 
5203     if (SetModelDefaults () == ERROR)
5204         return (ERROR);
5205 
5206     if (SetUpAnalysis (&globalSeed) == ERROR)
5207         return (ERROR);
5208 
5209     /* set default names for some output file names based on processed file */
5210     strcpy (sumtParams.sumtFileName, inputFileName);
5211     strcpy (sumtParams.sumtOutfile, inputFileName);
5212     strcpy (sumpParams.sumpFileName, inputFileName);
5213     strcpy (sumpParams.sumpOutfile, inputFileName);
5214     strcpy (comptreeParams.comptOutfile, inputFileName);
5215 
5216     if (chainParams.numRuns == 1)
5217         {
5218         sprintf (comptreeParams.comptFileName1, "%s.t", inputFileName);
5219         sprintf (comptreeParams.comptFileName2, "%s.t", inputFileName);
5220         }
5221     else /* if (chainParams.numRuns > 1) */
5222         {
5223         sprintf (comptreeParams.comptFileName1, "%s.run1.t", inputFileName);
5224         sprintf (comptreeParams.comptFileName2, "%s.run2.t", inputFileName);
5225         }
5226 
5227     if (chainParams.numRuns == 1)
5228         sprintf (plotParams.plotFileName, "%s.p", inputFileName);
5229     else /* if (chainParams.numRuns > 1) */
5230         sprintf (plotParams.plotFileName, "%s.run1.p", inputFileName);
5231 
5232     strcpy (chainParams.chainFileName, inputFileName);
5233 
5234     if (chainParams.numRuns > 1)
5235         MrBayesPrint ("%s   Setting output file names to \"%s.run<i>.<p|t>\"\n", spacer, chainParams.chainFileName);
5236     else
5237         MrBayesPrint ("%s   Setting output file names to \"%s.<p|t>\"\n", spacer, chainParams.chainFileName);
5238 
5239 #   if 0
5240     for (i=0; i<numChar; i++)
5241         {
5242         int     j;
5243         MrBayesPrint ("%4d -- ", i+1);
5244         for (j=0; j<numTaxa; j++)
5245             MrBayesPrint ("%2d ", matrix[pos(j,i,numChar)]);
5246         MrBayesPrint ("\n");
5247         }
5248 #   endif
5249 
5250     return (NO_ERROR);
5251 }
5252 
5253 
DoMatrixParm(char * parmName,char * tkn)5254 int DoMatrixParm (char *parmName, char *tkn)
5255 {
5256     int             i, j, charCode=0, index;
5257     MrBFlt          charValue;
5258 
5259     expecting  = Expecting(ALPHA);
5260     expecting |= Expecting(QUESTIONMARK);
5261     expecting |= Expecting(DASH);
5262     expecting |= Expecting(NUMBER);
5263     expecting |= Expecting(ASTERISK);
5264     expecting |= Expecting(EXCLAMATIONMARK);
5265     expecting |= Expecting(PERCENT);
5266     expecting |= Expecting(WEIRD);
5267     expecting |= Expecting(VERTICALBAR);
5268     expecting |= Expecting(SEMICOLON);
5269     expecting |= Expecting(LEFTPAR);
5270     expecting |= Expecting(RIGHTPAR);
5271     expecting |= Expecting(LEFTCURL);
5272     expecting |= Expecting(RIGHTCURL);
5273 
5274     if (defTaxa == NO || defChars == NO)
5275         {
5276         MrBayesPrint ("%s   Number of taxa and characters needs to be defined before matrix is read\n", spacer);
5277         goto errorExit;
5278         }
5279     if (inDataBlock == NO && inCharactersBlock == NO)
5280         {
5281         MrBayesPrint ("%s   Must be in data or characters block to read in character matrix\n", spacer);
5282         goto errorExit;
5283         }
5284 
5285     if (isFirstMatrixRead == YES)
5286         {
5287         foundNewLine = YES;
5288         isFirstInterleavedBlock = YES;
5289         taxonCount = 0;
5290         isNegative = NO;
5291         }
5292     isFirstMatrixRead = NO;
5293 
5294     /* allow line breaks in non-interleaved matrices */
5295     if (isInterleaved == NO)
5296         {
5297         if (foundNewLine == YES && taxonCount > 0)
5298             {
5299             if (taxaInfo[taxonCount-1].charCount < numChar)
5300                 foundNewLine = NO;
5301             }
5302         }
5303 
5304     if (taxonCount >= numTaxa && foundNewLine == YES)
5305         {
5306         if (isInterleaved == YES)
5307             {
5308             taxonCount = 0;
5309             isFirstInterleavedBlock = NO;
5310             }
5311         else
5312             {
5313             MrBayesPrint ("%s   Too many taxa in matrix\n", spacer);
5314             goto errorExit;
5315             }
5316         }
5317 
5318     if (taxaInfo[0].charCount > 4010)
5319         i = 1;  /* FIXME: Not used (from clang static analyzer) */
5320 
5321     if (foundNewLine == YES)
5322         {
5323         /* Should be a taxon. */
5324         if (isFirstInterleavedBlock == YES)
5325             {
5326             /* If this is the first interleaved block, then we need to add the taxon
5327                to the set of taxon names unless there is already a defined taxon set. */
5328             if (strlen(tkn)>99)
5329                 {
5330                 MrBayesPrint ("%s   Taxon name %s is too long. Maximun 99 characters is allowed.\n", spacer, tkn);
5331                 goto errorExit;
5332                 }
5333             if (isTaxsetDef == NO && AddString (&taxaNames, taxonCount, tkn) == ERROR)
5334                 {
5335                 MrBayesPrint ("%s   Problem adding taxon %s to taxon set\n", spacer, tkn);
5336                 goto errorExit;
5337                 }
5338             if (numTaxa < 10)
5339                 MrBayesPrint ("%s   Taxon %d -> %s\n", spacer, taxonCount+1, tkn);
5340             else if (numTaxa < 100 && numTaxa >= 10)
5341                 MrBayesPrint ("%s   Taxon %2d -> %s\n", spacer, taxonCount+1, tkn);
5342             else if (numTaxa < 1000 && numTaxa >= 100)
5343                 MrBayesPrint ("%s   Taxon %3d -> %s\n", spacer, taxonCount+1, tkn);
5344             else
5345                 MrBayesPrint ("%s   Taxon %4d -> %s\n", spacer, taxonCount+1, tkn);
5346             }
5347         else
5348             {
5349             /* If this is not the first interleaved block, then we need to
5350                check to see if taxon name is present and in correct place. */
5351             if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
5352                 {
5353                 MrBayesPrint ("%s   Could not find taxon %s in list of taxa\n", spacer, tkn);
5354                 goto errorExit;
5355                 }
5356             if (index != taxonCount)
5357                 {
5358                 MrBayesPrint ("%s   Could not find taxon %s in correct position in list of taxa\n", spacer, tkn);
5359                 goto errorExit;
5360                 }
5361             }
5362         foundNewLine = NO;
5363         isNegative = NO;
5364         taxonCount++;
5365         }
5366     else
5367         {
5368         /* Should be a character (either continuous or otherwise). */
5369         if (charInfo[taxaInfo[taxonCount-1].charCount].charType == CONTINUOUS)
5370             {
5371             /* If we have a CONTINUOUS character, then the entire token should either be
5372                a number or a dash (for a negative sign). */
5373             if (!strcmp(tkn, "-"))
5374                 {
5375                 /* Dealing with a negative number. We will multiply the next tkn, which
5376                    had better be a number, by -1. */
5377                 isNegative = YES;
5378                 }
5379             else
5380                 {
5381                 /* We have a number, we hope. */
5382                 if (tkn[0] == matchId)
5383                     {
5384                     /* If the token is a matchchar, then things are simple. */
5385                     if (taxonCount == 1)
5386                         {
5387                         MrBayesPrint ("%s   Matching characters cannot be in first taxon\n", spacer);
5388                         goto errorExit;
5389                         }
5390                     charCode = matrix[pos(0,taxaInfo[taxonCount-1].charCount,numChar)];
5391                     matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount,numChar)] = charCode;
5392                     }
5393                 else
5394                     {
5395                     /* Otherwise, we have a number. Check that it is a valid number first... */
5396                     if (!IsIn(tkn[0],"0123456789."))
5397                         {
5398                         MrBayesPrint ("%s   Expecting a number for the continuous character\n", spacer);
5399                         goto errorExit;
5400                         }
5401                     /* ... and then put the character into the matrix. Note that matrix
5402                        is defined as an integer, but we may have floating precision continuous
5403                        characters. To get around this, we multiply the value of the character
5404                        by 1000 before putting it into matrix. We will divide by 1000 later on
5405                        when/if we use the characters. */
5406                     sscanf (tkn, "%lf", &charValue);
5407                     charValue *= 1000.0;
5408                     if (isNegative == YES)
5409                         {
5410                         charValue *= -1.0;
5411                         isNegative = NO;
5412                         }
5413                     /*MrBayesPrint ("%d \n", (int)charValue);*/
5414                     matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = (int)charValue;
5415                     }
5416                 }
5417             }
5418         else
5419             {
5420             /* Otherwise, we are dealing with a run-of-the-mill character, and we
5421                cannot expect the entire token to contain only a single character. We
5422                must, therefore, go through the token character-by-character. */
5423             i = 0;
5424             while (tkn[i] != '\0')
5425                 {
5426                 /*MrBayesPrint ("%c", tkn[i]);*/
5427                 if (tkn[i] == matchId)
5428                     {
5429                     if (taxonCount == 1)
5430                         {
5431                         MrBayesPrint ("%s   Matching characters cannot be in first taxon\n", spacer);
5432                         goto errorExit;
5433                         }
5434                     charCode = matrix[pos(0,taxaInfo[taxonCount-1].charCount,numChar)];
5435                     matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = charCode;
5436                     }
5437                 else
5438                     {
5439                     if ((tkn[i] == ')' && isInAmbig == YES) || (tkn[i] == '}' && isInPoly == YES))
5440                         {
5441                         isInAmbig = isInPoly = NO;
5442                         charCode = theAmbigChar;
5443                         j = CharacterNumber (charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType);
5444                         if (j > charInfo[taxaInfo[taxonCount-1].charCount].numStates)
5445                             charInfo[taxaInfo[taxonCount-1].charCount].numStates = j;
5446                         matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = charCode;
5447                         theAmbigChar = 0;
5448                         }
5449                     else if ((tkn[i] == '(' && isInAmbig == YES) || (tkn[i] == '{' && isInPoly == YES))
5450                         {
5451                         if (isInAmbig == YES)
5452                             MrBayesPrint ("%s   Found an inappropriate \"(\"\n", spacer);
5453                         else
5454                             MrBayesPrint ("%s   Found an inappropriate \"{\"\n", spacer);
5455                         goto errorExit;
5456                         }
5457                     else if (isInAmbig == YES || isInPoly == YES)
5458                         {
5459                         if (tkn[i] == ',')
5460                             expecting |= Expecting (COMMA);
5461                         else
5462                             {
5463                             if (CharacterCode(tkn[i], &charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType) == ERROR)
5464                                 goto errorExit;
5465                             if (charCode == MISSING || charCode == GAP)
5466                                 goto errorExit;
5467                             theAmbigChar |= charCode;
5468                             expecting ^= Expecting (COMMA);
5469                             }
5470                         }
5471                     else if (tkn[i] == '{' && isInPoly == NO && isInAmbig == NO)
5472                         {
5473                         isInPoly = YES;
5474                         matrixHasPoly = YES;
5475                         theAmbigChar = 0;
5476                         }
5477                     else if (tkn[i] == '(' && isInPoly == NO && isInAmbig == NO)
5478                         {
5479                         isInAmbig = YES;
5480                         theAmbigChar = 0;
5481                         }
5482                     else if (tkn[i] == '(' && isInPoly == NO && isInAmbig == NO)
5483                         {
5484                         isInAmbig = YES;
5485                         theAmbigChar = 0;
5486                         }
5487                     else
5488                         {
5489                         if (CharacterCode(tkn[i], &charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType) == ERROR)
5490                             {
5491                             MrBayesPrint ("%s   Error while reading character position %d (charCode %d)\n", spacer, taxaInfo[taxonCount-1].charCount+1, charCode);
5492                             goto errorExit;
5493                             }
5494                         if (charCode != MISSING && charCode != GAP)
5495                             {
5496                             j = CharacterNumber (charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType);
5497                             if (j > charInfo[taxaInfo[taxonCount-1].charCount].numStates)
5498                                 charInfo[taxaInfo[taxonCount-1].charCount].numStates = j;
5499                             }
5500                         matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = charCode;
5501                         }
5502                     }
5503                 i++;
5504                 }
5505             }
5506         }
5507 
5508     return (NO_ERROR);
5509     errorExit:
5510         numTaxa=taxonCount;
5511         FreeMatrix();
5512         return (ERROR);
5513 }
5514 
5515 
DoNexusParm(char * parmName,char * tkn)5516 int DoNexusParm (char *parmName, char *tkn)
5517 {
5518     if (!strcmp(parmName, "NEXUS"))
5519         {
5520         MrBayesPrint ("%s   Expecting NEXUS formatted file\n", spacer);
5521         expecting = Expecting(COMMAND);
5522         }
5523     else
5524         {
5525         MrBayesPrint ("%s   Found %s\n", spacer, tkn);
5526         return (ERROR);
5527         }
5528 
5529     return (NO_ERROR);
5530 }
5531 
5532 
DoOutgroup(void)5533 int DoOutgroup (void)
5534 {
5535     MrBayesPrint ("%s   Setting outgroup to taxon \"%s\"\n", spacer, taxaNames[outGroupNum]);
5536     return (NO_ERROR);
5537 }
5538 
5539 
DoOutgroupParm(char * parmName,char * tkn)5540 int DoOutgroupParm (char *parmName, char *tkn)
5541 {
5542     int     index, tempInt;
5543 
5544     if (expecting == Expecting(ALPHA))
5545         {
5546         if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
5547             {
5548             MrBayesPrint ("%s   Could not find taxon %s in list of taxa\n", spacer, tkn);
5549             return (ERROR);
5550             }
5551         outGroupNum = index;
5552 
5553         expecting = Expecting(SEMICOLON);
5554         }
5555     else if (expecting == Expecting(NUMBER))
5556         {
5557         if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
5558             {
5559             /* OK, as we expect, the taxon is not a digit. So, now we assume that
5560                the user is assigning the outgroup by its number */
5561             sscanf (tkn, "%d", &tempInt);
5562             if (tempInt < 1 || tempInt > numTaxa)
5563                 {
5564                 MrBayesPrint ("%s   Taxon number %d is out of range\n", spacer, tempInt);
5565                 return (ERROR);
5566                 }
5567             outGroupNum = tempInt - 1;
5568             }
5569         else
5570             {
5571             outGroupNum = index;
5572             }
5573 
5574         expecting = Expecting(SEMICOLON);
5575         }
5576     else
5577         return (ERROR);
5578 
5579     return (NO_ERROR);
5580 }
5581 
5582 
DoPairs(void)5583 int DoPairs (void)
5584 {
5585     MrBayesPrint ("\n");
5586     MrBayesPrint ("%s   Successfully defined character pairings\n", spacer);
5587 
5588     defPairs = YES;
5589     foundFirst = NO;
5590 
5591     return (NO_ERROR);
5592 }
5593 
5594 
DoPairsParm(char * parmName,char * tkn)5595 int DoPairsParm (char *parmName, char *tkn)
5596 {
5597     int     i, tempInt;
5598 
5599     if (defMatrix == NO)
5600         {
5601         MrBayesPrint ("%s   A matrix must be specified before you can define pairs of characters\n", spacer);
5602         return (ERROR);
5603         }
5604 
5605     if (defPairs == YES)
5606         {
5607         MrBayesPrint ("%s   Character pairs have been previously defined \n", spacer);
5608         MrBayesPrint ("%s   Now overwriting old pairings\n", spacer);
5609         for (i=0; i<numChar; i++)
5610             charInfo[i].pairsId = 0;
5611         defPairs = NO;
5612         }
5613 
5614     if (foundFirst == NO)
5615         {
5616         /* this is the first time in */
5617         pairId = 1;
5618         firstPair = YES;
5619         foundFirst = YES;
5620         MrBayesPrint ("%s   Defining character pairings:\n\n", spacer);
5621         MrBayesPrint ("%s      Pair --  First Second \n", spacer);
5622         }
5623 
5624     if (expecting == Expecting(NUMBER))
5625         {
5626         sscanf (tkn, "%d", &tempInt);
5627         if (tempInt <= 0 || tempInt > numChar)
5628             {
5629             MrBayesPrint ("\n");
5630             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
5631             for (i=0; i<numChar; i++)
5632                 charInfo[i].pairsId = 0;
5633             return (ERROR);
5634             }
5635         tempInt--;
5636 
5637         if (charInfo[tempInt].pairsId != 0)
5638             {
5639             MrBayesPrint ("\n");
5640             MrBayesPrint ("%s   Character number %d has already been included in a pairing\n", spacer, tempInt+1);
5641             for (i=0; i<numChar; i++)
5642                 charInfo[i].pairsId = 0;
5643             return (ERROR);
5644             }
5645         if (charInfo[tempInt].charType != DNA && charInfo[tempInt].charType != RNA)
5646             {
5647             MrBayesPrint ("\n");
5648             MrBayesPrint ("%s  Pairings may only include nucleotide data\n", spacer);
5649             if (charInfo[tempInt].charType == PROTEIN)
5650                 MrBayesPrint ("%s  Character %d is an amino acid character\n", spacer, tempInt+1);
5651             else if (charInfo[tempInt].charType == RESTRICTION)
5652                 MrBayesPrint ("%s  Character %d is a restriction site character\n", spacer, tempInt+1);
5653             else if (charInfo[tempInt].charType == STANDARD)
5654                 MrBayesPrint ("%s  Character %d is a \"standard\" character\n", spacer, tempInt+1);
5655             else if (charInfo[tempInt].charType == CONTINUOUS)
5656                 MrBayesPrint ("%s  Character %d is a continuously varying character\n", spacer, tempInt+1);
5657             for (i=0; i<numChar; i++)
5658                 charInfo[i].pairsId = 0;
5659             return (ERROR);
5660             }
5661 
5662         charInfo[tempInt].pairsId = pairId;
5663 
5664         if (firstPair == YES)
5665             {
5666             MrBayesPrint ("%s      %4d --  %5d  ", spacer, pairId, tempInt+1);
5667             expecting  = Expecting(COLON);
5668             firstPair = NO;
5669             }
5670         else
5671             {
5672             MrBayesPrint ("%5d\n", tempInt+1);
5673             expecting  = (Expecting(COMMA) | Expecting(SEMICOLON));
5674             firstPair = YES;
5675             }
5676         }
5677     else if (expecting == Expecting(COMMA))
5678         {
5679         pairId++;
5680         expecting = Expecting(NUMBER);
5681         }
5682     else if (expecting == Expecting(COLON))
5683         {
5684         expecting = Expecting(NUMBER);
5685         }
5686     else
5687         {
5688         for (i=0; i<numChar; i++)
5689             charInfo[i].pairsId = 0;
5690         return (ERROR);
5691         }
5692 
5693     return (NO_ERROR);
5694 }
5695 
5696 
DoPartition(void)5697 int DoPartition (void)
5698 {
5699     int     i, *partTypes;
5700 
5701     /* add set to tempSet */
5702     if (fromI >= 0)
5703         if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
5704             return (ERROR);
5705 
5706     /* check that all characters are included */
5707     for (i=0; i<numChar; i++)
5708         {
5709         /* MrBayesPrint ("%4d %4d \n", i, tempSet[i]); */
5710         if (tempSet[i] == 0)
5711             {
5712             MrBayesPrint ("%s   Character %d not included in partition\n", spacer, i+1);
5713             return (ERROR);
5714             }
5715         }
5716 
5717 
5718     /* check how many partitions were found against how many were expected */
5719     if (whichPartition != numDivisions - 1)
5720         {
5721         MrBayesPrint ("%s   Did not find correct number of partitions (expecting %d, found %d)\n", spacer, numDivisions, whichPartition + 1);
5722         return (ERROR);
5723         }
5724 
5725     partTypes = (int *) SafeCalloc (numDivisions, sizeof(int));
5726     if (!partTypes)
5727         return ERROR;
5728 
5729     /* make certain that the partition labels go from 1 - numDivisions, inclusive */
5730     for (i=0; i<numChar; i++)
5731         partTypes[tempSet[i] - 1] = -1; //partTypes is temporary used here not as an indicator of partition type
5732     for (i=0; i<numDivisions; i++)
5733         {
5734         if (partTypes[i] == 0)
5735             {
5736             MrBayesPrint ("%s   Could not find a single character for division %d\n", spacer, i+1);
5737             return (ERROR);
5738             }
5739         }
5740 
5741     /* check if partition overruns data types */
5742     for (i=0; i<numChar; i++)
5743         {
5744         if (partTypes[ tempSet[i]-1 ] == -1)
5745             partTypes[ tempSet[i]-1 ] = charInfo[i].charType;
5746         else
5747             {
5748             if (partTypes[ tempSet[i]-1 ] != charInfo[i].charType)
5749                 {
5750                 MrBayesPrint ("%s   There are two different data types for partition division %d\n", spacer, tempSet[i]);
5751                 free (partTypes);
5752                 return (ERROR);
5753                 }
5754             }
5755         }
5756     free (partTypes);
5757 
5758     /* add name to list of valid partitions */
5759     if (AddString (&partitionNames, numDefinedPartitions, tempSetName) == ERROR)
5760         {
5761         MrBayesPrint ("%s   Problem adding partition %s to list\n", spacer, tempSetName);
5762         return (ERROR);
5763         }
5764 
5765     /* add new partition */
5766     for (i=0; i<numChar; i++) {
5767         partitionId[i] = (int *) SafeRealloc ((void *)(partitionId[i]), ((size_t)numDefinedPartitions + 1) * sizeof(int));
5768         if (!partitionId[i])
5769             return ERROR;
5770     }
5771 
5772     /* set new partition */
5773     for (i=0; i<numChar; i++)
5774         partitionId[i][numDefinedPartitions] = tempSet[i];
5775 
5776     /* increment number of defined partitions */
5777     numDefinedPartitions++;
5778 
5779     return (NO_ERROR);
5780 }
5781 
5782 
DoPartitionParm(char * parmName,char * tkn)5783 int DoPartitionParm (char *parmName, char *tkn)
5784 {
5785     int     i, index, tempInt;
5786 
5787     if (defMatrix == NO)
5788         {
5789         MrBayesPrint ("%s   A matrix must be specified before partitions can be defined\n", spacer);
5790         return (ERROR);
5791         }
5792 
5793     if (expecting == Expecting(PARAMETER))
5794         {
5795         /* set Partition () ******************************************************************/
5796         if (!strcmp(parmName, "Xxxxxxxxxx"))
5797             {
5798             /* check size of partition name */
5799             if (strlen(tkn) > 99)
5800                 {
5801                 MrBayesPrint ("%s   Partition name is too long. Max 100 characters\n", spacer);
5802                 return (ERROR);
5803                 }
5804 
5805             /* check to see if the name has already been used as a partition */
5806             if (numDefinedPartitions > 1)
5807                 {
5808                 if (CheckString (partitionNames, numDefinedPartitions, tkn, &index) == ERROR)
5809                     {
5810                     /* if the partition name has not been used, then we should have an ERROR returned */
5811                     /* we _want_ to be here */
5812 
5813                     }
5814                 else
5815                     {
5816                     MrBayesPrint ("%s   Partition name '%s' has been used previously\n", spacer, tkn);
5817                     return (ERROR);
5818                     }
5819                 }
5820 
5821             /* add the name temporarily to tempSetName */
5822             strcpy (tempSetName, tkn);
5823 
5824             /* clear tempSet */
5825             for (i=0; i<numChar; i++)
5826                 tempSet[i] = 0;
5827 
5828             fromI = toJ = everyK = -1;
5829             foundDash = foundSlash = NO;
5830             whichPartition = 0;
5831             foundFirst = NO;
5832             numDivisions = 0;
5833             MrBayesPrint ("%s   Defining partition called '%s'\n", spacer, tkn);
5834             expecting = Expecting(EQUALSIGN);
5835             }
5836         else
5837             return (ERROR);
5838         }
5839     else if (expecting == Expecting(EQUALSIGN))
5840         {
5841         expecting = Expecting(NUMBER);
5842         }
5843     else if (expecting == Expecting(ALPHA))
5844         {
5845         /* We are defining a partition in terms of a character set (called tkn, here). We should be able
5846            to find tkn in the list of character set names. If we cannot, then we have a problem and
5847            return an error. */
5848         if (numCharSets < 1)
5849             {
5850             MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
5851             return (ERROR);
5852             }
5853         if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
5854             {
5855             MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
5856             return (ERROR);
5857             }
5858         /* add characters from charset tkn to new tempSet */
5859         for (i=0; i<numChar; i++)
5860             {
5861             if (IsBitSet (i, charSet[index]) == YES)
5862                 tempSet[i] = whichPartition + 1;
5863             }
5864         fromI = toJ = everyK = -1;
5865 
5866         expecting  = Expecting(ALPHA);
5867         expecting |= Expecting(NUMBER);
5868         expecting |= Expecting(SEMICOLON);
5869         expecting |= Expecting(COMMA);
5870         }
5871     else if (expecting == Expecting(NUMBER))
5872         {
5873         if (foundFirst == NO)
5874             {
5875             sscanf (tkn, "%d", &tempInt);
5876             numDivisions = tempInt;
5877             expecting  = Expecting(COLON);
5878             foundFirst = YES;
5879             }
5880         else
5881             {
5882             if (strlen(tkn) == 1 && tkn[0] == '.')
5883                 tempInt = numChar;
5884             else
5885                 sscanf (tkn, "%d", &tempInt);
5886             if (tempInt <= 0 || tempInt > numChar)
5887                 {
5888                 MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
5889                 return (ERROR);
5890                 }
5891             tempInt--;
5892             if (foundDash == YES)
5893                 {
5894                 if (fromI >= 0)
5895                     toJ = tempInt;
5896                 else
5897                     {
5898                     MrBayesPrint ("%s   Improperly formatted partition\n", spacer);
5899                     return (ERROR);
5900                     }
5901                 foundDash = NO;
5902                 }
5903             else if (foundSlash == YES)
5904                 {
5905                 tempInt++;
5906                 if (tempInt <= 1)
5907                     {
5908                     MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
5909                     return (ERROR);
5910                     }
5911                 if (fromI >= 0 && toJ >= 0 && fromI < toJ)
5912                     everyK = tempInt;
5913                 else
5914                     {
5915                     MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
5916                     return (ERROR);
5917                     }
5918                 foundSlash = NO;
5919                 }
5920             else
5921                 {
5922                 if (fromI >= 0 && toJ < 0)
5923                     {
5924                     if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
5925                         return (ERROR);
5926                     fromI = tempInt;
5927                     }
5928                 else if (fromI < 0 && toJ < 0)
5929                     {
5930                     fromI = tempInt;
5931                     }
5932                 else if (fromI >= 0 && toJ >= 0 && everyK < 0)
5933                     {
5934                     if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
5935                         return (ERROR);
5936                     fromI = tempInt;
5937                     toJ = everyK = -1;
5938                     }
5939                 else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
5940                     {
5941                     if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
5942                         return (ERROR);
5943                     fromI = tempInt;
5944                     toJ = everyK = -1;
5945                     }
5946                 else
5947                     {
5948                     MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
5949                         {
5950                         return (ERROR);
5951                         }
5952                     }
5953                 }
5954 
5955             expecting  = Expecting(ALPHA);
5956             expecting |= Expecting(NUMBER);
5957             expecting |= Expecting(SEMICOLON);
5958             expecting |= Expecting(DASH);
5959             expecting |= Expecting(BACKSLASH);
5960             expecting |= Expecting(COMMA);
5961             }
5962         }
5963     else if (expecting == Expecting(COMMA))
5964         {
5965         /* add set to tempSet */
5966         if (fromI >= 0)
5967             if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
5968                 return (ERROR);
5969 
5970         fromI = toJ = everyK = -1;
5971         foundDash = foundSlash = NO;
5972         whichPartition++;
5973         if (whichPartition > numDivisions)
5974             {
5975             MrBayesPrint ("%s   Too many partitions of the data (expecting %d)\n", spacer, numDivisions);
5976             return (ERROR);
5977             }
5978         expecting  = Expecting(NUMBER);
5979         expecting |= Expecting(ALPHA);
5980         }
5981     else if (expecting == Expecting(COLON))
5982         {
5983         expecting  = Expecting(NUMBER);
5984         expecting |= Expecting(ALPHA);
5985         }
5986     else if (expecting == Expecting(DASH))
5987         {
5988         foundDash = YES;
5989         expecting = Expecting(NUMBER);
5990         }
5991     else if (expecting == Expecting(BACKSLASH))
5992         {
5993         foundSlash = YES;
5994         expecting = Expecting(NUMBER);
5995         }
5996     else
5997         return (ERROR);
5998 
5999     return (NO_ERROR);
6000 }
6001 
6002 
DoRestore(void)6003 int DoRestore (void)
6004 {
6005     int         i, alreadyDone;
6006 
6007     MrBayesPrint ("%s   Restore taxa\n", spacer);
6008 
6009     /* add set to tempSet */
6010     if (fromI >= 0 && toJ < 0)
6011         {
6012         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6013             return (ERROR);
6014         }
6015     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
6016         {
6017         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6018             return (ERROR);
6019         }
6020     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
6021         {
6022         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6023             return (ERROR);
6024         }
6025 
6026     /* merge tempSet with excludedTaxa */
6027     alreadyDone = NO;
6028     for (i=0; i<numTaxa; i++)
6029         {
6030         if (tempSet[i] == 1)
6031             {
6032             if (taxaInfo[i].isDeleted == NO && alreadyDone == NO)
6033                 {
6034                 MrBayesPrint ("%s   Some taxa already included\n", spacer);
6035                 alreadyDone = YES;
6036                 }
6037             taxaInfo[i].isDeleted = NO;
6038             }
6039         }
6040 
6041     SetLocalTaxa();
6042     if (SetUpAnalysis(&globalSeed) == ERROR)
6043         return ERROR;
6044 
6045     /* show tempSet (for debugging) */
6046 #   if 0
6047     for (i=0; i<numTaxa; i++)
6048         MrBayesPrint ("%4d  %4d\n", i+1, tempSet[i]);
6049 #   endif
6050 
6051     return (NO_ERROR);
6052 }
6053 
6054 
DoRestoreParm(char * parmName,char * tkn)6055 int DoRestoreParm (char *parmName, char *tkn)
6056 {
6057     int     i, index, tempInt;
6058 
6059     if (defMatrix == NO)
6060         {
6061         MrBayesPrint ("%s   A matrix must be specified before you can restore taxa\n", spacer);
6062         return (ERROR);
6063         }
6064 
6065     if (foundFirst == NO)
6066         {
6067         /* this is the first time in */
6068         fromI = toJ = everyK = -1;
6069         foundDash = NO;
6070         for (i=0; i<numTaxa; i++) /* clear tempSet */
6071             tempSet[i] = 0;
6072         foundFirst = YES;
6073         }
6074 
6075     if (expecting == Expecting(ALPHA))
6076         {
6077         if (IsSame ("All", tkn) == SAME || IsSame ("All", tkn) == CONSISTENT_WITH)
6078             {
6079             for (i=0; i<numTaxa; i++)
6080                 tempSet[i] = 1;
6081             }
6082         else
6083             {
6084             if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
6085                 {
6086                 /* we are using a pre-defined taxa set */
6087                 if (numTaxaSets < 1)
6088                     {
6089                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
6090                     return (ERROR);
6091                     }
6092                 if (CheckString (taxaSetNames, numTaxaSets, tkn, &index) == ERROR)
6093                     {
6094                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
6095                     return (ERROR);
6096                     }
6097                 /* add taxa from taxset tkn to new tempSet */
6098                 for (i=0; i<numTaxa; i++)
6099                     {
6100                     if (IsBitSet (i, taxaSet[index]) == YES)
6101                         tempSet[i] = 1;
6102                     }
6103                 }
6104             else
6105                 {
6106                 /* we found the taxon name */
6107                 if (fromI >= 0 && toJ < 0)
6108                     {
6109                     if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6110                         return (ERROR);
6111                     }
6112                 else if (fromI >= 0 && toJ >= 0)
6113                     {
6114                     if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6115                         return (ERROR);
6116                     }
6117                 tempSet[index] = 1;
6118                 }
6119             fromI = toJ = everyK = -1;
6120             }
6121 
6122         expecting  = Expecting(ALPHA);
6123         expecting |= Expecting(NUMBER);
6124         expecting |= Expecting(SEMICOLON);
6125         }
6126     else if (expecting == Expecting(NUMBER))
6127         {
6128         if (strlen(tkn) == 1 && !strcmp(tkn, "."))
6129             {
6130             tempInt = numTaxa;
6131             }
6132         else
6133             {
6134             sscanf (tkn, "%d", &tempInt);
6135             if (tempInt <= 0 || tempInt > numTaxa)
6136                 {
6137                 MrBayesPrint ("%s   Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa);
6138                 return (ERROR);
6139                 }
6140             }
6141         tempInt--;
6142         if (foundDash == YES)
6143             {
6144             if (fromI >= 0)
6145                 toJ = tempInt;
6146             else
6147                 {
6148                 MrBayesPrint ("%s   Improperly formatted restore set\n", spacer);
6149                 return (ERROR);
6150                 }
6151             foundDash = NO;
6152             }
6153         else
6154             {
6155             if (fromI >= 0 && toJ < 0)
6156                 {
6157                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6158                     return (ERROR);
6159                 fromI = tempInt;
6160                 }
6161             else if (fromI < 0 && toJ < 0)
6162                 {
6163                 fromI = tempInt;
6164                 }
6165             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
6166                 {
6167                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6168                     return (ERROR);
6169                 fromI = tempInt;
6170                 toJ = everyK = -1;
6171                 }
6172             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
6173                 {
6174                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6175                     return (ERROR);
6176                 fromI = tempInt;
6177                 toJ = everyK = -1;
6178                 }
6179             else
6180                 {
6181                 MrBayesPrint ("%s   Improperly formatted restore set\n", spacer);
6182                     {
6183                     return (ERROR);
6184                     }
6185                 }
6186             }
6187         expecting  = Expecting(ALPHA);
6188         expecting |= Expecting(NUMBER);
6189         expecting |= Expecting(SEMICOLON);
6190         expecting |= Expecting(DASH);
6191         }
6192     else if (expecting == Expecting(DASH))
6193         {
6194         foundDash = YES;
6195         expecting = Expecting(NUMBER);
6196         }
6197     else
6198         return (ERROR);
6199 
6200     return (NO_ERROR);
6201 }
6202 
6203 
DoSet(void)6204 int DoSet (void)
6205 {
6206     return (NO_ERROR);
6207 }
6208 
6209 
DoSetParm(char * parmName,char * tkn)6210 int DoSetParm (char *parmName, char *tkn)
6211 {
6212     int         index;
6213     char        tempStr[100];
6214     int         tempI;
6215 
6216     if (expecting == Expecting(PARAMETER))
6217         {
6218         expecting = Expecting(EQUALSIGN);
6219         }
6220     else
6221         {
6222         /* set Autoclose (autoClose) **********************************************************/
6223         if (!strcmp(parmName, "Autoclose"))
6224             {
6225             if (expecting == Expecting(EQUALSIGN))
6226                 expecting = Expecting(ALPHA);
6227             else if (expecting == Expecting(ALPHA))
6228                 {
6229                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6230                     {
6231                     if (!strcmp(tempStr, "Yes"))
6232                         autoClose = YES;
6233                     else
6234                         autoClose = NO;
6235                     }
6236                 else
6237                     {
6238                     MrBayesPrint ("%s   Invalid argument for autoclose\n", spacer);
6239                     return (ERROR);
6240                     }
6241                 if (autoClose == YES)
6242                     MrBayesPrint ("%s   Setting autoclose to yes\n", spacer);
6243                 else
6244                     MrBayesPrint ("%s   Setting autoclose to no\n", spacer);
6245                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6246                 }
6247             else
6248                 return (ERROR);
6249             }
6250         /* set Nowarnings (noWarn) **********************************************************/
6251         else if (!strcmp(parmName, "Nowarnings"))
6252             {
6253             if (expecting == Expecting(EQUALSIGN))
6254                 expecting = Expecting(ALPHA);
6255             else if (expecting == Expecting(ALPHA))
6256                 {
6257                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6258                     {
6259                     if (!strcmp(tempStr, "Yes"))
6260                         noWarn = YES;
6261                     else
6262                         noWarn = NO;
6263                     }
6264                 else
6265                     {
6266                     MrBayesPrint ("%s   Invalid argument for nowarnings\n", spacer);
6267                     return (ERROR);
6268                     }
6269                 if (noWarn == YES)
6270                     MrBayesPrint ("%s   Setting nowarnings to yes\n", spacer);
6271                 else
6272                     MrBayesPrint ("%s   Setting nowarnings to no\n", spacer);
6273                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6274                 }
6275             else
6276                 return (ERROR);
6277             }
6278         /* set Quitonerror (quitOnError) **************************************************/
6279         else if (!strcmp(parmName, "Quitonerror"))
6280             {
6281             if (expecting == Expecting(EQUALSIGN))
6282                 expecting = Expecting(ALPHA);
6283             else if (expecting == Expecting(ALPHA))
6284                 {
6285                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6286                     {
6287                     if (!strcmp(tempStr, "Yes"))
6288                         quitOnError = YES;
6289                     else
6290                         quitOnError = NO;
6291                     }
6292                 else
6293                     {
6294                     MrBayesPrint ("%s   Invalid argument for quitonerror\n", spacer);
6295                     return (ERROR);
6296                     }
6297                 if (quitOnError == YES)
6298                     MrBayesPrint ("%s   Setting quitonerror to yes\n", spacer);
6299                 else
6300                     MrBayesPrint ("%s   Setting quitonerror to no\n", spacer);
6301                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6302                 }
6303             else
6304                 return (ERROR);
6305             }
6306         /* set Autoreplace (autoOverwrite) **************************************************/
6307         else if (!strcmp(parmName, "Autoreplace"))
6308             {
6309             if (expecting == Expecting(EQUALSIGN))
6310                 expecting = Expecting(ALPHA);
6311             else if (expecting == Expecting(ALPHA))
6312                 {
6313                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6314                     {
6315                     if (!strcmp(tempStr, "Yes"))
6316                         {
6317                         autoOverwrite = YES;
6318                         MrBayesPrint ("%s   Setting autoreplace to yes\n", spacer);
6319                         }
6320                     else
6321                         {
6322                         autoOverwrite = NO;
6323                         MrBayesPrint ("%s   Setting autoreplace to no\n", spacer);
6324                         }
6325                     }
6326                 else
6327                     {
6328                     MrBayesPrint ("%s   Invalid argument for autoreplace\n", spacer);
6329                     return (ERROR);
6330                     }
6331                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6332                 }
6333             else
6334                 return (ERROR);
6335             }
6336         /* set Scientific (scientific) *********************************************/
6337         else if (!strcmp(parmName, "Scientific"))
6338             {
6339             if (expecting == Expecting(EQUALSIGN))
6340                 expecting = Expecting(ALPHA);
6341             else if (expecting == Expecting(ALPHA))
6342                 {
6343                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6344                     {
6345                     if (!strcmp(tempStr, "Yes"))
6346                         scientific = YES;
6347                     else
6348                         scientific = NO;
6349                     }
6350                 else
6351                     {
6352                     MrBayesPrint ("%s   Invalid argument for Scientific\n", spacer);
6353                     return (ERROR);
6354                     }
6355                 if (scientific == YES)
6356                     MrBayesPrint ("%s   Setting Scientific to Yes\n", spacer);
6357                 else
6358                     MrBayesPrint ("%s   Setting Scientific to No\n", spacer);
6359                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6360                 }
6361             else
6362                 return (ERROR);
6363             }
6364         /* set Userlevel (userLevel) **********************************************************/
6365         else if (!strcmp(parmName, "Userlevel"))
6366             {
6367             if (expecting == Expecting(EQUALSIGN))
6368                 expecting = Expecting(ALPHA);
6369             else if (expecting == Expecting(ALPHA))
6370                 {
6371                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6372                     {
6373                     if (!strcmp(tempStr, "Standard"))
6374                         userLevel = STANDARD_USER;
6375                     else if (!strcmp (tempStr,"Developer"))
6376                         userLevel = DEVELOPER;
6377                     }
6378                 else
6379                     {
6380                     MrBayesPrint ("%s   Invalid argument for userlevel\n", spacer);
6381                     return (ERROR);
6382                     }
6383                 MrBayesPrint ("%s   Setting userlevel to %s\n", spacer, tempStr);
6384                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6385                     return ERROR;
6386                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6387                 }
6388             else
6389                 return (ERROR);
6390             }
6391         /* set Npthreads (number of pthreads) ****************************************************/
6392         else if (!strcmp(parmName, "Npthreads"))
6393             {
6394             if (expecting == Expecting(EQUALSIGN))
6395                 expecting = Expecting(NUMBER);
6396             else if (expecting == Expecting(NUMBER))
6397                 {
6398                 sscanf (tkn, "%d", &tempI);
6399                 nPThreads = tempI;
6400                 MrBayesPrint ("%s   Setting Npthreads to %d\n", spacer, nPThreads);
6401                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6402                 }
6403             else
6404                 return (ERROR);
6405             }
6406         /* set Precision (number of decimals) ****************************************************/
6407         else if (!strcmp(parmName, "Precision"))
6408             {
6409             if (expecting == Expecting(EQUALSIGN))
6410                 expecting = Expecting(NUMBER);
6411             else if (expecting == Expecting(NUMBER))
6412                 {
6413                 sscanf (tkn, "%d", &tempI);
6414                 if (tempI < 3 || tempI > 15)
6415                     {
6416                     MrBayesPrint ("%s   Precision must be in the range 3 to 15\n", spacer);
6417                     return ERROR;
6418                     }
6419                 precision = tempI;
6420                 MrBayesPrint ("%s   Setting Precision to %d\n", spacer, precision);
6421                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6422                 }
6423             else
6424                 return (ERROR);
6425             }
6426         /* set Partition (partitionNum) *******************************************************/
6427         else if (!strcmp(parmName, "Partition"))
6428             {
6429             if (defMatrix == NO)
6430                 {
6431                 MrBayesPrint ("%s   A character matrix must be defined first\n", spacer);
6432                 return (ERROR);
6433                 }
6434             if (expecting == Expecting(EQUALSIGN))
6435                 expecting = Expecting(ALPHA) | Expecting(NUMBER);
6436             else if (expecting == Expecting(ALPHA))
6437                 {
6438                 /* first check to see if name is there */
6439                 if (CheckString (partitionNames, numDefinedPartitions, tkn, &index) == ERROR)
6440                     {
6441                     MrBayesPrint ("%s   Could not find \"%s\" as a defined partition\n", spacer, tkn);
6442                     return (ERROR);
6443                     }
6444                 if (SetPartition (index) == ERROR)
6445                     return ERROR;
6446                 if (numCurrentDivisions == 1)
6447                     MrBayesPrint ("%s   Setting %s as the partition (does not divide up characters).\n", spacer, tkn);
6448                 else
6449                     MrBayesPrint ("%s   Setting %s as the partition, dividing characters into %d parts.\n", spacer, tkn, numCurrentDivisions);
6450                 if (SetModelDefaults () == ERROR)
6451                     return (ERROR);
6452                 if (SetUpAnalysis (&globalSeed) == ERROR)
6453                     return (ERROR);
6454                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6455                 }
6456             else if (expecting == Expecting(NUMBER))
6457                 {
6458                 sscanf (tkn, "%d", &index);
6459                 if (index > numDefinedPartitions)
6460                     {
6461                     MrBayesPrint ("%s   Partition number %d is not a valid partition. Only %d partitions\n", spacer, index, numDefinedPartitions);
6462                     MrBayesPrint ("%s   have been defined.\n", spacer);
6463                     return (ERROR);
6464                     }
6465                 if (index < 1)
6466                     {
6467                     MrBayesPrint ("%s   Partition number %d is not a valid partition. Must be between 1 and %d.\n", spacer, index+1, numDefinedPartitions);
6468                     return (ERROR);
6469                     }
6470                 if (SetPartition (index) == ERROR)
6471                     return ERROR;
6472                 if (numCurrentDivisions == 1)
6473                     MrBayesPrint ("%s   Setting %s as the partition (does not divide up characters).\n", spacer, partitionNames[index]);
6474                 else
6475                     MrBayesPrint ("%s   Setting %s as the partition, dividing characters into %d parts.\n", spacer, partitionNames[index], numCurrentDivisions);
6476                 if (SetModelDefaults () == ERROR)
6477                     return (ERROR);
6478                 if (SetUpAnalysis (&globalSeed) == ERROR)
6479                     return (ERROR);
6480                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6481                 }
6482             else
6483                 return (ERROR);
6484             }
6485         /* set Speciespartition (speciespartitionNum) *******************************************************/
6486         else if (!strcmp(parmName, "Speciespartition"))
6487             {
6488             if (defTaxa == NO)
6489                 {
6490                 MrBayesPrint ("%s   A taxaset must be defined first\n", spacer);
6491                 return (ERROR);
6492                 }
6493             if (expecting == Expecting(EQUALSIGN))
6494                 expecting = Expecting(ALPHA) | Expecting(NUMBER);
6495             else if (expecting == Expecting(ALPHA))
6496                 {
6497                 /* first check to see if name is there */
6498                 if (CheckString (speciespartitionNames, numDefinedSpeciespartitions, tkn, &index) == ERROR)
6499                     {
6500                     MrBayesPrint ("%s   Could not find \"%s\" as a defined speciespartition\n", spacer, tkn);
6501                     return (ERROR);
6502                     }
6503                 if (SetSpeciespartition (index) == ERROR)
6504                     return ERROR;
6505                 MrBayesPrint ("%s   Setting %s as the speciespartition, dividing taxa into %d species.\n", spacer, tkn, numSpecies);
6506                 if (SetModelDefaults () == ERROR)
6507                     return (ERROR);
6508                 if (SetUpAnalysis (&globalSeed) == ERROR)
6509                     return (ERROR);
6510                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6511                 }
6512             else if (expecting == Expecting(NUMBER))
6513                 {
6514                 sscanf (tkn, "%d", &index);
6515                 if (index > numDefinedSpeciespartitions)
6516                     {
6517                     MrBayesPrint ("%s   Speciespartition number %d is not valid. Only %d speciespartitions\n", spacer, index, numDefinedSpeciespartitions);
6518                     MrBayesPrint ("%s   have been defined.\n", spacer);
6519                     return (ERROR);
6520                     }
6521                 if (index < 1)
6522                     {
6523                     MrBayesPrint ("%s   Speciespartition number %d is not valid. Must be between 1 and %d.\n", spacer, index, numDefinedSpeciespartitions);
6524                     return (ERROR);
6525                     }
6526                 if (SetSpeciespartition (index-1) == ERROR)
6527                     return ERROR;
6528                 MrBayesPrint ("%s   Setting %s as the speciespartition, dividing taxa into %d species.\n", spacer, speciespartitionNames[index-1], numSpecies);
6529                 if (SetModelDefaults () == ERROR)
6530                     return (ERROR);
6531                 if (SetUpAnalysis (&globalSeed) == ERROR)
6532                     return (ERROR);
6533                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6534                 }
6535             else
6536                 return (ERROR);
6537             }
6538         /* set Seed (global variable globalSeed) ****************************************************/
6539         else if (!strcmp(parmName, "Seed"))
6540             {
6541             if (expecting == Expecting(EQUALSIGN))
6542                 expecting = Expecting(NUMBER);
6543             else if (expecting == Expecting(NUMBER))
6544                 {
6545                 sscanf (tkn, "%d", &tempI);
6546                 if (tempI == 0 || tempI == 2147483647)
6547                     {
6548                     MrBayesPrint ("%s   Error: Seed can be any natural number except 0 and 2147483647\n", spacer);
6549                     return (ERROR);
6550                     }
6551                 globalSeed = tempI;
6552                 MrBayesPrint ("%s   Setting seed to %ld\n", spacer, globalSeed);
6553                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6554                 }
6555             else
6556                 return (ERROR);
6557             }
6558         /* set Swapseed (global variable swapSeed) ***************************************************************/
6559         else if (!strcmp(parmName, "Swapseed"))
6560             {
6561             if (expecting == Expecting(EQUALSIGN))
6562                 expecting = Expecting(NUMBER);
6563             else if (expecting == Expecting(NUMBER))
6564                 {
6565                 sscanf (tkn, "%d", &tempI);
6566                 if (tempI == 0 || tempI == 2147483647)
6567                     {
6568                     MrBayesPrint ("%s   Error: Swapseed can be any natural number except 0 and 2147483647\n", spacer);
6569                     return (ERROR);
6570                     }
6571                 swapSeed = tempI;
6572                 MrBayesPrint ("%s   Setting swapseed to %ld\n", spacer, swapSeed);
6573                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6574                 }
6575             else
6576                 return (ERROR);
6577             }
6578         /* set Dir (global variable workingDir) ***************************************************************/
6579         else if (!strcmp(parmName, "Dir"))
6580             {
6581             if (expecting == Expecting(EQUALSIGN))
6582                 {
6583                 expecting = Expecting(ALPHA);
6584                 readWord = YES;
6585                 }
6586             else if (expecting == Expecting(ALPHA))
6587                 {
6588                 if (strlen(tkn)>99)
6589                     {
6590                     MrBayesPrint ("%s   Maximum allowed length of working directory name is 99 characters. The given name:\n", spacer);
6591                     MrBayesPrint ("%s      '%s'\n", spacer,tkn);
6592                     MrBayesPrint ("%s   has %d characters.\n", spacer,strlen(tkn));
6593                     return (ERROR);
6594                     }
6595                 strcpy (workingDir, tkn);
6596 #   if defined (WIN_VERSION)
6597                 /* Reformat to Windows with trailing '\' */
6598                 for (index=0; index<(int)strlen(workingDir); index++)
6599                     {
6600                     if (workingDir[index] == '/')
6601                         workingDir[index] = '\\';
6602                     }
6603                 if (strlen(workingDir) > 0 && workingDir[strlen(workingDir)-1] != '\\')
6604                     strcat(workingDir,"\\");
6605 #   else
6606                 /* Reformat to Unix with trailing '/' */
6607                 for (index=0; index<(int)strlen(workingDir); index++)
6608                     {
6609                     if (workingDir[index] == '\\')
6610                         workingDir[index] = '/';
6611                     }
6612                 if (strlen(workingDir) > 0 && workingDir[strlen(workingDir)-1] != '/')
6613                     strcat(workingDir,"/");
6614 #   endif
6615                 MrBayesPrint ("%s   Setting working directory to \"%s\"\n", spacer, workingDir);
6616                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6617                 }
6618             else
6619                 return (ERROR);
6620             }
6621         /* set Usebeagle (global variable BEAGLE usage) ***************************************************************/
6622         else if (!strcmp(parmName, "Usebeagle"))
6623             {
6624             if (expecting == Expecting(EQUALSIGN))
6625                 expecting = Expecting(ALPHA);
6626             else if (expecting == Expecting(ALPHA))
6627                 {
6628 #   if defined (BEAGLE_ENABLED)
6629                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6630                     {
6631                     if (!strcmp(tempStr, "Yes"))
6632                         tryToUseBEAGLE = YES;
6633                     else
6634                         tryToUseBEAGLE = NO;
6635                     }
6636                 else
6637                     {
6638                     MrBayesPrint ("%s   Invalid argument for usebeagle\n", spacer);
6639                     return (ERROR);
6640                     }
6641                 if (tryToUseBEAGLE == YES)
6642                     MrBayesPrint ("%s   Setting usebeagle to yes\n", spacer);
6643                 else
6644                     MrBayesPrint ("%s   Setting usebeagle to no\n", spacer);
6645 #   else
6646                 BeagleNotLinked();
6647 #   endif
6648                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6649                     return ERROR;
6650                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6651                 }
6652             else
6653                 return (ERROR);
6654             }
6655         /* set Beagle resource number (global variable BEAGLE flag) ****************************************/
6656         else if (!strcmp(parmName, "Beagleresource"))
6657             {
6658             if (expecting == Expecting(EQUALSIGN))
6659                 expecting =  Expecting(NUMBER);
6660             else if (expecting == Expecting(NUMBER))
6661                 {
6662 #   if defined (BEAGLE_ENABLED)
6663                 sscanf (tkn, "%d", &tempI);
6664                 if (tempI < 0)
6665                     {
6666                     MrBayesPrint ("%s   Beagleresource must be a valid resource number or 99 to disable resource selection\n", spacer);
6667                     return ERROR;
6668                     }
6669                 beagleResourceNumber = tempI;
6670                 if (beagleResourceNumber == 99)
6671                     MrBayesPrint ("%s   Setting Beagleresource to %d (auto)\n", spacer, beagleResourceNumber);
6672                 else
6673                     MrBayesPrint ("%s   Setting Beagleresource to %d\n", spacer, beagleResourceNumber);
6674 #   else
6675                 BeagleNotLinked();
6676 #   endif
6677                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6678                     return ERROR;
6679                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6680                 }
6681             else
6682                 return (ERROR);
6683             }
6684         /* set Beagle resources requirements (global variable BEAGLE flag) ****************************************/
6685         else if (!strcmp(parmName, "Beagledevice"))
6686             {
6687             if (expecting == Expecting(EQUALSIGN))
6688                 expecting = Expecting(ALPHA);
6689             else if (expecting == Expecting(ALPHA))
6690                 {
6691 #   if defined (BEAGLE_ENABLED)
6692                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6693                     {
6694                     long oldFlags = beagleFlags;
6695                     if (!strcmp(tempStr, "Gpu"))
6696                         {
6697                         beagleFlags &= ~BEAGLE_FLAG_PROCESSOR_CPU;
6698                         beagleFlags |= BEAGLE_FLAG_PROCESSOR_GPU;
6699                         BeagleAddGPUDevicesToList(&beagleResource, &beagleResourceCount);
6700                         }
6701                     else
6702                         {
6703                         beagleFlags &= ~BEAGLE_FLAG_PROCESSOR_GPU;
6704                         beagleFlags |= BEAGLE_FLAG_PROCESSOR_CPU;
6705                         BeagleRemoveGPUDevicesFromList(&beagleResource, &beagleResourceCount);
6706                         }
6707                     if (BeagleCheckFlagCompatability(beagleFlags) == NO) {
6708                         beagleFlags = oldFlags;
6709                         }
6710                     else {
6711                         if (beagleFlags & BEAGLE_FLAG_PROCESSOR_GPU)
6712                             MrBayesPrint ("%s   Setting beagledevice to GPU\n", spacer);
6713                         else
6714                             MrBayesPrint ("%s   Setting beagledevice to CPU\n", spacer);
6715                         }
6716                     }
6717                 else
6718                     {
6719                     MrBayesPrint ("%s   Invalid argument for beagledevice\n", spacer);
6720                     return (ERROR);
6721                     }
6722 #   else
6723                 BeagleNotLinked();
6724 #   endif
6725                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6726                     return ERROR;
6727                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6728                 }
6729             else
6730                 return (ERROR);
6731             }
6732         else if (!strcmp(parmName, "Beagleprecision"))
6733             {
6734             if (expecting == Expecting(EQUALSIGN))
6735                 expecting = Expecting(ALPHA);
6736             else if (expecting == Expecting(ALPHA))
6737                 {
6738 #   if defined (BEAGLE_ENABLED)
6739                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6740                     {
6741                     long oldFlags = beagleFlags;
6742                     if (!strcmp(tempStr, "Single"))
6743                         {
6744                         beagleFlags &= ~BEAGLE_FLAG_PRECISION_DOUBLE;
6745                         beagleFlags |= BEAGLE_FLAG_PRECISION_SINGLE;
6746                         }
6747                     else
6748                         {
6749                         beagleFlags &= ~BEAGLE_FLAG_PRECISION_SINGLE;
6750                         beagleFlags |= BEAGLE_FLAG_PRECISION_DOUBLE;
6751                         }
6752                     if (BeagleCheckFlagCompatability(beagleFlags) == NO) {
6753                         beagleFlags = oldFlags;
6754                         }
6755                     else {
6756                         if (beagleFlags & BEAGLE_FLAG_PRECISION_DOUBLE)
6757                             MrBayesPrint ("%s   Setting beagleprecision to double\n", spacer);
6758                         else
6759                             MrBayesPrint ("%s   Setting beagleprecision to single\n", spacer);
6760                         }
6761                     }
6762                 else
6763                     {
6764                     MrBayesPrint ("%s   Invalid argument for beagleprecision\n", spacer);
6765                     return (ERROR);
6766                     }
6767 #   else
6768                 BeagleNotLinked();
6769 #   endif
6770                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6771                     return ERROR;
6772                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6773                 }
6774             else
6775                 return (ERROR);
6776             }
6777         else if (!strcmp(parmName, "Beagleopenmp"))
6778             {
6779             if (expecting == Expecting(EQUALSIGN))
6780                 expecting = Expecting(ALPHA);
6781             else if (expecting == Expecting(ALPHA))
6782                 {
6783 #   if defined (BEAGLE_ENABLED)
6784                 MrBayesPrint ("%s   Setting beagleopenmp no longer supported\n", spacer);
6785                 return (ERROR);
6786 #   else
6787                 BeagleNotLinked();
6788 #   endif
6789                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6790                     return ERROR;
6791                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6792                 }
6793             else
6794                 return (ERROR);
6795             }
6796         else if (!strcmp(parmName, "Beaglefreq"))
6797             {
6798             if (expecting == Expecting(EQUALSIGN))
6799                 expecting = Expecting(NUMBER);
6800             else if (expecting == Expecting(NUMBER))
6801                 {
6802 #   if defined (BEAGLE_ENABLED)
6803                 sscanf (tkn, "%d", &tempI);
6804                 if (tempI < 0)
6805                     {
6806                     MrBayesPrint ("%s   Beaglefreq must be greater than 0\n", spacer);
6807                     return ERROR;
6808                     }
6809                 beagleScalingFrequency= tempI;
6810                 MrBayesPrint ("%s   Setting Beaglefreq to %d\n", spacer, beagleScalingFrequency);
6811 #   else
6812                 BeagleNotLinked();
6813 #   endif
6814                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6815                     return ERROR;
6816                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6817                 }
6818             else
6819                 return (ERROR);
6820             }
6821         else if (!strcmp(parmName, "Beaglesse"))
6822             {
6823             if (expecting == Expecting(EQUALSIGN))
6824                 expecting = Expecting(ALPHA);
6825             else if (expecting == Expecting(ALPHA))
6826                 {
6827 #   if defined (BEAGLE_ENABLED)
6828                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6829                     {
6830                     long oldFlags = beagleFlags;
6831                     if (!strcmp(tempStr, "Yes"))
6832                         {
6833                         beagleFlags |= BEAGLE_FLAG_VECTOR_SSE;
6834                         }
6835                     else
6836                         {
6837                         beagleFlags &= ~BEAGLE_FLAG_VECTOR_SSE;
6838                         beagleFlags |= BEAGLE_FLAG_VECTOR_NONE;
6839                         }
6840                     if (BeagleCheckFlagCompatability(beagleFlags) == NO) {
6841                         beagleFlags = oldFlags;
6842                         }
6843                     else {
6844                         if (beagleFlags & BEAGLE_FLAG_VECTOR_SSE)
6845                             MrBayesPrint ("%s   Setting beaglesse to Yes\n", spacer);
6846                         else
6847                             MrBayesPrint ("%s   Setting beaglesse to No\n", spacer);
6848                         }
6849                     }
6850                 else
6851                     {
6852                     MrBayesPrint ("%s   Invalid argument for beaglesse\n", spacer);
6853                     return (ERROR);
6854                     }
6855 #   else
6856                 BeagleNotLinked();
6857 #   endif
6858                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6859                     return ERROR;
6860                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6861                 }
6862             else
6863                 return (ERROR);
6864             }
6865         else if (!strcmp(parmName, "Beaglethreads"))
6866             {
6867             if (expecting == Expecting(EQUALSIGN))
6868                 expecting = Expecting(ALPHA);
6869             else if (expecting == Expecting(ALPHA))
6870                 {
6871 #   if defined (BEAGLE_V3_ENABLED)
6872                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6873                     {
6874                     if (!strcmp(tempStr, "Yes"))
6875                         {
6876                         beagleFlags &= ~BEAGLE_FLAG_THREADING_NONE;
6877                         beagleFlags |= BEAGLE_FLAG_THREADING_CPP;
6878                         }
6879                     else
6880                         {
6881                         beagleFlags &= ~BEAGLE_FLAG_THREADING_CPP;
6882                         beagleFlags |= BEAGLE_FLAG_THREADING_NONE;
6883                         }
6884                     if (beagleFlags & BEAGLE_FLAG_THREADING_CPP)
6885                         MrBayesPrint ("%s   Setting beaglethreads to Yes\n", spacer);
6886                     else
6887                         MrBayesPrint ("%s   Setting beaglethreads to No\n", spacer);
6888                     }
6889                 else
6890                     {
6891                     MrBayesPrint ("%s   Invalid argument for beaglethreads\n", spacer);
6892                     return (ERROR);
6893                     }
6894 #   else
6895                 BeagleThreadsNotAvailable();
6896 #   endif
6897                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6898                     return ERROR;
6899                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6900                 }
6901             else
6902                 return (ERROR);
6903             }
6904         else if (!strcmp(parmName, "Beaglethreadcount"))
6905             {
6906             if (expecting == Expecting(EQUALSIGN))
6907                 expecting = Expecting(NUMBER);
6908             else if (expecting == Expecting(NUMBER))
6909                 {
6910 #   if defined (BEAGLE_V3_ENABLED)
6911                 sscanf (tkn, "%d", &tempI);
6912                 if (tempI < 1)
6913                     {
6914                     MrBayesPrint ("%s   Beaglethreadcount must be a valid number of threads\n", spacer);
6915                     return ERROR;
6916                     }
6917                 beagleThreadCount = tempI;
6918                 if (beagleThreadCount == 1)
6919                     {
6920                     MrBayesPrint ("%s   Setting beaglethreadcount to %d (single-threaded)\n", spacer, beagleThreadCount);
6921                     beagleFlags &= ~BEAGLE_FLAG_THREADING_CPP;
6922                     beagleFlags |= BEAGLE_FLAG_THREADING_NONE;
6923                     }
6924                 else if (beagleThreadCount == 99)
6925                     {
6926                     MrBayesPrint ("%s   Setting beaglethreadcount to %d (auto-threading)\n", spacer, beagleThreadCount);
6927                     beagleFlags &= ~BEAGLE_FLAG_THREADING_NONE;
6928                     beagleFlags |= BEAGLE_FLAG_THREADING_CPP;
6929                     }
6930                 else
6931                     {
6932                     MrBayesPrint ("%s   Setting beaglethreadcount to %d\n", spacer, beagleThreadCount);
6933                     beagleFlags &= ~BEAGLE_FLAG_THREADING_NONE;
6934                     beagleFlags |= BEAGLE_FLAG_THREADING_CPP;
6935                     }
6936 #   else
6937                 BeagleThreadsNotAvailable();
6938 #   endif
6939                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6940                     return ERROR;
6941                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6942                 }
6943             else
6944                 return (ERROR);
6945             }
6946         else if (!strcmp(parmName, "Beaglefloattips"))
6947             {
6948             if (expecting == Expecting(EQUALSIGN))
6949                 expecting = Expecting(ALPHA);
6950             else if (expecting == Expecting(ALPHA))
6951                 {
6952 #   if defined (BEAGLE_V3_ENABLED)
6953                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6954                     {
6955                     if (!strcmp(tempStr, "Yes"))
6956                         {
6957                         beagleAllFloatTips = YES;
6958                         }
6959                     else
6960                         {
6961                         beagleAllFloatTips = NO;
6962                         }
6963                     if (beagleAllFloatTips)
6964                         MrBayesPrint ("%s   Setting beaglefloattips to Yes\n", spacer);
6965                     else
6966                         MrBayesPrint ("%s   Setting beaglefloattips to No\n", spacer);
6967                     }
6968                 else
6969                     {
6970                     MrBayesPrint ("%s   Invalid argument for beaglefloattips\n", spacer);
6971                     return (ERROR);
6972                     }
6973 #   else
6974                 MrBayesPrint ("%s   Beaglefloattips setting requires BEAGLE v3.1 and higher.\n", spacer);
6975 #   endif
6976                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6977                     return ERROR;
6978                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6979                 }
6980             else
6981                 return (ERROR);
6982             }
6983 #if 0
6984         else if (!strcmp(parmName, "Beaglevec"))
6985             {
6986             if (expecting == Expecting(EQUALSIGN))
6987                 expecting = Expecting(ALPHA);
6988             else if (expecting == Expecting(ALPHA))
6989                 {
6990 #   if defined (BEAGLE_ENABLED)
6991                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6992                     {
6993                     long oldFlags = beagleFlags;
6994                     if (!strcmp(tempStr, "Sse"))
6995                         {
6996                         beagleFlags |= BEAGLE_FLAG_VECTOR_SSE;
6997                         beagleFlags &= ~BEAGLE_FLAG_VECTOR_AVX;
6998                         }
6999                     else if (!strcmp(tempStr, "Avx"))
7000                         {
7001                         beagleFlags |= ~BEAGLE_FLAG_VECTOR_AVX;
7002                         beagleFlags &= ~BEAGLE_FLAG_VECTOR_SSE;
7003                         }
7004                     else if (!strcmp(tempStr, "None"))
7005                         {
7006                         beagleFlags &= ~BEAGLE_FLAG_VECTOR_SSE;
7007                         beagleFlags &= ~BEAGLE_FLAG_VECTOR_AVX;
7008                         }
7009                     else
7010                         {
7011                         MrBayesPrint("%s   Unrecognized argument for beaglevec\n", spacer);
7012                         }
7013                     MrBayesPrint ("%s   Setting beaglevec to %s\n", spacer, tempStr);
7014                     }
7015                 else
7016                     {
7017                     MrBayesPrint ("%s   Invalid argument for beagleopenmp\n", spacer);
7018                     return (ERROR);
7019                     }
7020 #   else
7021                 BeagleNotLinked();
7022 #   endif
7023                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
7024                     return ERROR;
7025                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7026                 }
7027             else
7028                 return (ERROR);
7029             }
7030 #endif
7031         else if (!strcmp(parmName, "Beaglescaling"))
7032             {
7033             if (expecting == Expecting(EQUALSIGN))
7034                 expecting = Expecting(ALPHA);
7035             else if (expecting == Expecting(ALPHA))
7036                 {
7037 #   if defined (BEAGLE_ENABLED)
7038                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7039                     {
7040                     if (!strcmp(tempStr, "Always"))
7041                         {
7042                         beagleScalingScheme = MB_BEAGLE_SCALE_ALWAYS;
7043                         }
7044                     else
7045                         {
7046                         beagleScalingScheme = MB_BEAGLE_SCALE_DYNAMIC;
7047                         }
7048 
7049                     if (beagleScalingScheme == MB_BEAGLE_SCALE_ALWAYS)
7050                         MrBayesPrint ("%s   Setting beaglescaling to Always\n", spacer);
7051                     else
7052                         MrBayesPrint ("%s   Setting beaglescaling to Dynamic\n", spacer);
7053                     }
7054                 else
7055                     {
7056                     MrBayesPrint ("%s   Invalid argument for beaglescaling\n", spacer);
7057                     return (ERROR);
7058                     }
7059 #   else
7060                 BeagleNotLinked();
7061 #   endif
7062                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
7063                     return ERROR;
7064                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7065                 }
7066             else
7067                 return (ERROR);
7068             }
7069         else
7070             return (ERROR);
7071         }
7072 
7073     return (NO_ERROR);
7074 }
7075 
7076 
DoShowMatrix(void)7077 int DoShowMatrix (void)
7078 {
7079     int         i, j, nameLen, start, finish, ct, longestName;
7080     char        tempStr[100], stride;
7081 
7082     if (defMatrix == NO)
7083         {
7084         MrBayesPrint ("%s   A character matrix must be defined first\n", spacer);
7085         return (ERROR);
7086         }
7087 
7088     longestName = 0;
7089     for (i=0; i<numTaxa; i++)
7090         {
7091         nameLen = (int) strlen(taxaNames[i]);
7092         if (nameLen > longestName)
7093             longestName = nameLen;
7094         }
7095 
7096     stride = 50;
7097     start = finish = 0;
7098     do
7099         {
7100         finish += stride;
7101         if (finish > numChar)
7102             finish = numChar;
7103 
7104         MrBayesPrint ("%s   ", spacer);
7105         for (j=0; j<longestName; j++)
7106             MrBayesPrint (" ");
7107         MrBayesPrint ("  ");
7108         MrBayesPrint ("%d\n", start+1);
7109 
7110         for (i=0; i<numTaxa; i++)
7111             {
7112             strcpy (tempStr, taxaNames[i]);
7113             nameLen = (int) strlen(tempStr);
7114 
7115             MrBayesPrint ("%s   ", spacer);
7116             if (nameLen >= longestName)
7117                 {
7118                 for (j=0; j<longestName; j++)
7119                     MrBayesPrint ("%c", tempStr[j]);
7120                 }
7121             else
7122                 {
7123                 MrBayesPrint ("%s", tempStr);
7124                 for (j=0; j<longestName-nameLen; j++)
7125                     MrBayesPrint (" ");
7126                 }
7127             MrBayesPrint ("  ");
7128 
7129             for (j=start; j<finish; j++)
7130                 {
7131                 ct = charInfo[j].charType;
7132                 if (ct == DNA || ct == RNA)
7133                     MrBayesPrint ("%c", WhichNuc(matrix[pos(i,j,numChar)]));
7134                 else if (ct == PROTEIN)
7135                     MrBayesPrint ("%c", WhichAA(matrix[pos(i,j,numChar)]));
7136                 else if (ct == STANDARD)
7137                     MrBayesPrint ("%c", WhichStand(matrix[pos(i,j,numChar)]));
7138                 else if (ct == RESTRICTION)
7139                     MrBayesPrint ("%c", WhichRes(matrix[pos(i,j,numChar)]));
7140                 else if (ct == CONTINUOUS)
7141                     {
7142                     if (WhichCont(matrix[pos(i,j,numChar)]) < 0.0)
7143                         MrBayesPrint (" %2.2lf", WhichCont(matrix[pos(i,j,numChar)]));
7144                     else
7145                         MrBayesPrint ("  %2.2lf", WhichCont(matrix[pos(i,j,numChar)]));
7146                     }
7147                 else
7148                     {
7149                     MrBayesPrint ("%s   Unknown data type\n", spacer);
7150                     return (ERROR);
7151                     }
7152 
7153                 }
7154             MrBayesPrint ("\n");
7155             }
7156         MrBayesPrint ("\n");
7157         start = finish;
7158         } while (finish != numChar);
7159 
7160     return (NO_ERROR);
7161 }
7162 
7163 
DoShowUserTrees(void)7164 int DoShowUserTrees (void)
7165 {
7166     int         i;
7167 
7168     if (numUserTrees == 0)
7169         {
7170         MrBayesPrint ("%s   No user trees have been defined\n", spacer);
7171         }
7172     else
7173         {
7174         for (i=0; i<numUserTrees; i++)
7175             {
7176             MrBayesPrint ("\n   Tree #%d -- '%s':\n\n", i+1, userTree[i]->name);
7177             ShowConTree (stdout, userTree[i], 70, NO);
7178             MrBayesPrint ("\n");
7179             }
7180         }
7181 
7182     return (NO_ERROR);
7183 }
7184 
7185 
DoShowBeagle(void)7186 int DoShowBeagle (void)
7187 {
7188 #   if defined (BEAGLE_ENABLED)
7189     BeaglePrintResources();
7190 #   else
7191     BeagleNotLinked();
7192 #   endif
7193     return (NO_ERROR);
7194 }
7195 
7196 
DoTaxlabels(void)7197 int DoTaxlabels (void)
7198 {
7199     isTaxsetDef = YES;
7200 
7201     /* add default speciespartition name to list of valid speciespartitions */
7202     if (AddString (&speciespartitionNames, 0, "Default") == ERROR)
7203         {
7204         MrBayesPrint ("%s   Problem adding Default speciespartition to list\n", spacer);
7205         return (ERROR);
7206         }
7207 
7208     /* add default species name set */
7209     AddNameSet(&speciesNameSets, 0, taxaNames, numTaxa);
7210 
7211     /* set number of defined speciespartitions to 1 */
7212     numDefinedSpeciespartitions = 1;
7213 
7214     return (NO_ERROR);
7215 }
7216 
7217 
DoTaxlabelsParm(char * parmName,char * tkn)7218 int DoTaxlabelsParm (char *parmName, char *tkn)
7219 {
7220     int         index;
7221 
7222     if (inTaxaBlock == NO)
7223         {
7224         MrBayesPrint ("%s   You must be in a taxa block to read a taxlabels command\n", spacer);
7225         return (ERROR);
7226         }
7227 
7228     if (defTaxa == NO)
7229         {
7230         MrBayesPrint ("%s   The number of taxa must be given before a set of taxon labels can be read\n", spacer);
7231         return ERROR;
7232         }
7233 
7234     if (isTaxsetDef == YES)
7235         {
7236         MrBayesPrint ("%s   A set of taxon labels has already been defined\n", spacer);
7237         if (defMatrix == NO)
7238             if (WantTo ("Do you want to delete the current set of taxon labels") == NO)
7239                 return (SKIP_COMMAND);
7240             else
7241                 FreeTaxa();
7242         else
7243             if (WantTo ("Do you want to delete the current character matrix") == NO)
7244                 return (SKIP_COMMAND);
7245             else
7246                 FreeMatrix();
7247         }
7248 
7249     if (expecting == Expecting(ALPHA) ||
7250         expecting == Expecting(NUMBER))
7251         {
7252         if (CheckString (taxaNames, numNamedTaxa, tkn, &index) == ERROR)
7253             {
7254             if (strlen(tkn)>99)
7255                 {
7256                 MrBayesPrint ("%s   Taxon name %s is too long. Maximun 99 characters is allowed.\n", spacer, tkn);
7257                 return (ERROR);
7258                 }
7259             if (AddString (&taxaNames, numNamedTaxa, tkn) == ERROR)
7260                 {
7261                 MrBayesPrint ("%s   Problem adding label %s to list of taxon labels\n", spacer, tkn);
7262                 return (ERROR);
7263                 }
7264             numNamedTaxa++;
7265             }
7266         else
7267             {
7268             MrBayesPrint ("%s   Taxon label '%s' is included twice in list of taxon labels\n", spacer, tkn);
7269             return (ERROR);
7270             }
7271         if (numNamedTaxa < numTaxa)
7272             {
7273             expecting = Expecting(ALPHA);
7274             expecting |= Expecting(NUMBER);
7275             }
7276         else
7277             expecting |= Expecting(SEMICOLON);
7278         }
7279 
7280     return (NO_ERROR);
7281 }
7282 
7283 
DoSpeciespartition(void)7284 int DoSpeciespartition (void)
7285 {
7286     int     i, *partCount;
7287 
7288     /* add set to tempSet */
7289     if (fromI >= 0)
7290         if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
7291             {
7292             for (i=0; i<numDivisions; i++)
7293                 free(tempNames[i]);
7294             free (tempNames);
7295             tempNames = NULL;
7296             return (ERROR);
7297             }
7298 
7299     /* set numDivisions; not set while reading the speciespartition */
7300     numDivisions = whichPartition + 1;
7301 
7302     /* check that all species are included */
7303     for (i=0; i<numTaxa; i++)
7304         {
7305         if (tempSet[i] == 0)
7306             {
7307             MrBayesPrint ("%s   Tip %d not included in speciespartition\n", spacer, i+1);
7308             for (i=0; i<numDivisions; i++)
7309                 free(tempNames[i]);
7310             free (tempNames);
7311             tempNames = NULL;
7312             return (ERROR);
7313             }
7314         /*MrBayesPrint ("%4d %4d \n", i, tempSet[i]);*/
7315         }
7316 
7317     partCount = (int *) SafeCalloc (numDivisions, sizeof(int));
7318     if (!partCount)
7319         {
7320         for (i=0; i<numDivisions; i++)
7321             free(tempNames[i]);
7322         free (tempNames);
7323         tempNames = NULL;
7324         return ERROR;
7325         }
7326 
7327     /* make certain that the partition labels go from 1 - numTaxa, inclusive */
7328     for (i=0; i<numTaxa; i++)
7329         {
7330         if (tempSet[i] < 1 || tempSet[i] > numTaxa)
7331             {
7332             MrBayesPrint ("%s   Speciespartition index for tip %d out of bound (%d)\n", spacer, i+1, tempSet[i]);
7333             free (partCount);
7334             for (i=0; i<numDivisions; i++)
7335                 free(tempNames[i]);
7336             free (tempNames);
7337             tempNames = NULL;
7338             return (ERROR);
7339             }
7340         partCount[tempSet[i] - 1]++;
7341         }
7342     for (i=0; i<numDivisions; i++)
7343         {
7344         if (partCount[i] == 0)
7345             {
7346             MrBayesPrint ("%s   Could not find a single tip for species %d\n", spacer, i+1);
7347             free (partCount);
7348             for (i=0; i<numDivisions; i++)
7349                 free(tempNames[i]);
7350             free (tempNames);
7351             tempNames = NULL;
7352             return (ERROR);
7353             }
7354         }
7355     free (partCount);
7356 
7357     /* add name to list of valid partitions */
7358     if (AddString (&speciespartitionNames, numDefinedSpeciespartitions, tempSetName) == ERROR)
7359         {
7360         MrBayesPrint ("%s   Problem adding speciespartition %s to list\n", spacer, tempSetName);
7361         for (i=0; i<numDivisions; i++)
7362             free(tempNames[i]);
7363         free (tempNames);
7364         tempNames = NULL;
7365         return (ERROR);
7366         }
7367 
7368     /* add new partition */
7369     for (i=0; i<numTaxa; i++)
7370         {
7371         speciespartitionId[i] = (int *) SafeRealloc ((void *)(speciespartitionId[i]), ((size_t)numDefinedSpeciespartitions + 1) * sizeof(int));
7372         if (!speciespartitionId[i])
7373             {
7374             for (i=0; i<numDivisions; i++)
7375                 free(tempNames[i]);
7376             free (tempNames);
7377             tempNames = NULL;
7378             return ERROR;
7379             }
7380         }
7381 
7382     /* set new partition */
7383     for (i=0; i<numTaxa; i++)
7384         speciespartitionId[i][numDefinedSpeciespartitions] = tempSet[i];
7385 
7386     /* add new set of species names */
7387     AddNameSet(&speciesNameSets, numDefinedSpeciespartitions, tempNames, numDivisions);
7388 
7389     /* free species names */
7390     for (i=0; i<numDivisions; i++)
7391         free(tempNames[i]);
7392     free (tempNames);
7393     tempNames = NULL;
7394 
7395     /* increment number of defined partitions */
7396     numDefinedSpeciespartitions++;
7397 
7398     return (NO_ERROR);
7399 }
7400 
7401 
DoSpeciespartitionParm(char * parmName,char * tkn)7402 int DoSpeciespartitionParm (char *parmName, char *tkn)
7403 {
7404     int             i, index, tempInt;
7405 
7406     if (defTaxa == NO || numTaxa == 0)
7407         {
7408         MrBayesPrint ("%s   A matrix or taxaset must be specified before partitions can be defined\n", spacer);
7409         return (ERROR);
7410         }
7411 
7412     if (expecting == Expecting(PARAMETER))
7413         {
7414         /* set Speciespartition name ******************************************************************/
7415         if (!strcmp(parmName, "Xxxxxxxxxx"))
7416             {
7417             /* check size of partition name */
7418             if (strlen(tkn) > 99)
7419                 {
7420                 MrBayesPrint ("%s   Partition name is too long. Max 100 characters\n", spacer);
7421                 return (ERROR);
7422                 }
7423 
7424             /* check to see if the name has already been used as a partition */
7425             if (numDefinedSpeciespartitions > 0)
7426                 {
7427                 if (CheckString (speciespartitionNames, numDefinedSpeciespartitions, tkn, &index) == ERROR)
7428                     {
7429                     /* if the partition name has not been used, then we should have an ERROR returned */
7430                     /* we _want_ to be here */
7431 
7432                     }
7433                 else
7434                     {
7435                     MrBayesPrint ("%s   Speciespartition name '%s' has been used previously\n", spacer, tkn);
7436                     return (ERROR);
7437                     }
7438                 }
7439 
7440             /* add the name temporarily to tempSetName */
7441             strcpy (tempSetName, tkn);
7442 
7443             /* clear tempSet */
7444             for (i=0; i<numTaxa; i++)
7445                 tempSet[i] = 0;
7446 
7447             /* make sure tempNames is NULL */
7448             assert (tempNames == NULL);
7449 
7450             fromI = toJ = everyK = -1;
7451             foundDash = foundSlash = NO;
7452             whichPartition = 0;
7453             foundFirst = NO;
7454             numDivisions = 0;
7455             MrBayesPrint ("%s   Defining speciespartition called '%s'\n", spacer, tkn);
7456             expecting = Expecting(EQUALSIGN);
7457             }
7458         else
7459             return (ERROR);
7460         }
7461     else if (expecting == Expecting(EQUALSIGN))
7462         {
7463         expecting = Expecting(ALPHA);
7464         }
7465     else if (expecting == Expecting(ALPHA))
7466         {
7467         if (foundFirst == NO)
7468             {
7469             AddString(&tempNames, whichPartition, tkn);
7470             foundFirst = YES;
7471             expecting = Expecting(COLON);
7472             }
7473         else
7474             {
7475             /* We are defining a species partition in terms of a tip name (called tkn, here). We should be able
7476                to find tkn in the list of tip names. If we cannot, then we have a problem and
7477                return an error. */
7478             if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
7479                 {
7480                 MrBayesPrint ("%s   Could not find a tip called '%s'\n", spacer, tkn);
7481                 return (ERROR);
7482                 }
7483             /* add index of the tip named tkn to new tempSet */
7484             tempSet[index] = whichPartition + 1;
7485             fromI = toJ = everyK = -1;
7486 
7487             expecting  = Expecting(ALPHA);
7488             expecting |= Expecting(NUMBER);
7489             expecting |= Expecting(SEMICOLON);
7490             expecting |= Expecting(COMMA);
7491             }
7492         }
7493     else if (expecting == Expecting(NUMBER))
7494         {
7495         if (strlen(tkn) == 1 && tkn[0] == '.')
7496             tempInt = numTaxa;
7497         else
7498             sscanf (tkn, "%d", &tempInt);
7499         if (tempInt <= 0 || tempInt > numTaxa)
7500             {
7501             MrBayesPrint ("%s   Tip number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa);
7502             for (i=0; i<whichPartition; i++)
7503                 free(tempNames[i]);
7504             free (tempNames);
7505             tempNames = NULL;
7506             return (ERROR);
7507             }
7508         tempInt--;
7509         if (foundDash == YES)
7510             {
7511             if (fromI >= 0)
7512                 toJ = tempInt;
7513             else
7514                 {
7515                 MrBayesPrint ("%s   Improperly formatted speciespartition\n", spacer);
7516                 for (i=0; i<whichPartition; i++)
7517                     free(tempNames[i]);
7518                 free (tempNames);
7519                 tempNames = NULL;
7520                 return (ERROR);
7521                 }
7522             foundDash = NO;
7523             }
7524         else if (foundSlash == YES)
7525             {
7526             tempInt++;
7527             if (tempInt <= 1)
7528                 {
7529                 MrBayesPrint ("%s   Improperly formatted speciespartition\n", spacer);
7530                 for (i=0; i<whichPartition; i++)
7531                     free(tempNames[i]);
7532                 free (tempNames);
7533                 tempNames = NULL;
7534                 return (ERROR);
7535                 }
7536             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
7537                 everyK = tempInt;
7538             else
7539                 {
7540                 MrBayesPrint ("%s   Improperly formatted speciespartition\n", spacer);
7541                 for (i=0; i<whichPartition; i++)
7542                     free(tempNames[i]);
7543                 free (tempNames);
7544                 tempNames = NULL;
7545                 return (ERROR);
7546                 }
7547             foundSlash = NO;
7548             }
7549         else
7550             {
7551             if (fromI >= 0 && toJ < 0)
7552                 {
7553                 if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
7554                     {
7555                     for (i=0; i<whichPartition; i++)
7556                         free(tempNames[i]);
7557                     free (tempNames);
7558                     tempNames = NULL;
7559                     return (ERROR);
7560                     }
7561                 fromI = tempInt;
7562                 }
7563             else if (fromI < 0 && toJ < 0)
7564                 {
7565                 fromI = tempInt;
7566                 }
7567             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
7568                 {
7569                 if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
7570                     return (ERROR);
7571                 fromI = tempInt;
7572                 toJ = everyK = -1;
7573                 }
7574             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
7575                 {
7576                 if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
7577                     return (ERROR);
7578                 fromI = tempInt;
7579                 toJ = everyK = -1;
7580                 }
7581             else
7582                 {
7583                 MrBayesPrint ("%s   Improperly formatted speciespartition\n", spacer);
7584                     {
7585                     for (i=0; i<whichPartition; i++)
7586                         free(tempNames[i]);
7587                     free (tempNames);
7588                     tempNames = NULL;
7589                     return (ERROR);
7590                     }
7591                 }
7592             }
7593         expecting  = Expecting(ALPHA);
7594         expecting |= Expecting(NUMBER);
7595         expecting |= Expecting(SEMICOLON);
7596         expecting |= Expecting(DASH);
7597         expecting |= Expecting(BACKSLASH);
7598         expecting |= Expecting(COMMA);
7599         }
7600     else if (expecting == Expecting(COMMA))
7601         {
7602         /* add set to tempSet */
7603         if (fromI >= 0)
7604             if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
7605                 {
7606                 for (i=0; i<whichPartition; i++)
7607                     free(tempNames[i]);
7608                 free (tempNames);
7609                 tempNames = NULL;
7610                 return (ERROR);
7611                 }
7612 
7613         fromI = toJ = everyK = -1;
7614         foundDash = foundSlash = foundFirst = NO;
7615         whichPartition++;
7616         if (whichPartition > numTaxa)
7617             {
7618             MrBayesPrint ("%s   Too many speciespartitions (expecting maximum %d speciespartitions)\n", spacer, numTaxa);
7619             for (i=0; i<whichPartition; i++)
7620                 free(tempNames[i]);
7621             free (tempNames);
7622             tempNames = NULL;
7623             return (ERROR);
7624             }
7625         expecting  = Expecting(ALPHA);
7626         }
7627     else if (expecting == Expecting(COLON))
7628         {
7629         expecting  = Expecting(NUMBER);
7630         expecting |= Expecting(ALPHA);
7631         }
7632     else if (expecting == Expecting(DASH))
7633         {
7634         foundDash = YES;
7635         expecting = Expecting(NUMBER);
7636         }
7637     else if (expecting == Expecting(BACKSLASH))
7638         {
7639         foundSlash = YES;
7640         expecting = Expecting(NUMBER);
7641         }
7642     else
7643         {
7644         for (i=0; i<whichPartition; i++)
7645             free(tempNames[i]);
7646         free (tempNames);
7647         tempNames = NULL;
7648         return (ERROR);
7649         }
7650 
7651     return (NO_ERROR);
7652 }
7653 
7654 
DoTaxaset(void)7655 int DoTaxaset (void)
7656 {
7657     /* add set to tempSet */
7658     if (fromI >= 0 && toJ < 0)
7659         {
7660         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7661             return (ERROR);
7662         }
7663     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
7664         {
7665         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7666             return (ERROR);
7667         }
7668     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
7669         {
7670         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7671             return (ERROR);
7672         }
7673 
7674     /* add name to taxaSetNames */
7675     if (AddString (&taxaSetNames, numTaxaSets, tempSetName) == ERROR)
7676         {
7677         MrBayesPrint ("%s   Problem adding taxset %s to list\n", spacer, tempSetName);
7678         return (ERROR);
7679         }
7680 
7681     /* merge tempSet with taxaSet */
7682     AddBitfield (&taxaSet, numTaxaSets, tempSet, numTaxa);
7683 
7684     /* increment number of char sets */
7685     numTaxaSets++;
7686 
7687     /* show taxset (for debugging) */
7688 #   if 0
7689     for (i=0; i<numTaxa; i++)
7690         MrBayesPrint ("%4d  %4d\n", i+1, tempSet[i]);
7691 #   endif
7692 
7693     return (NO_ERROR);
7694 }
7695 
7696 
DoTaxasetParm(char * parmName,char * tkn)7697 int DoTaxasetParm (char *parmName, char *tkn)
7698 {
7699     int     i, index, tempInt;
7700 
7701     if (defMatrix == NO)
7702         {
7703         MrBayesPrint ("%s   A matrix must be specified before taxsets can be defined\n", spacer);
7704         return (ERROR);
7705         }
7706 
7707     if (expecting == Expecting(PARAMETER))
7708         {
7709         if (!strcmp(parmName, "Xxxxxxxxxx"))
7710             {
7711             /* check size of taxset name */
7712             if (strlen(tkn) > 99)
7713                 {
7714                 MrBayesPrint ("%s   Taxset name is too long\n", spacer);
7715                 return (ERROR);
7716                 }
7717 
7718             /* check to see if the name has already been used as a taxset */
7719             if (numTaxaSets > 0)
7720                 {
7721                 if (CheckString (taxaSetNames, numTaxaSets, tkn, &index) == ERROR)
7722                     {
7723                     /* if the taxset name has not been used, then we should have an ERROR returned */
7724                     /* we _want_ to be here */
7725 
7726                     }
7727                 else
7728                     {
7729                     MrBayesPrint ("%s   Taxset name has been used previously\n", spacer);
7730                     return (ERROR);
7731                     }
7732                 }
7733             else if (numTaxaSets > 30)
7734                 {
7735                 MrBayesPrint ("%s   You cannot define more than 30 taxsets\n", spacer);
7736                 return (ERROR);
7737                 }
7738 
7739             /* add the name to the taxa set */
7740             strcpy (tempSetName, tkn);
7741 
7742             /* clear tempSet */
7743             for (i=0; i<numTaxa; i++)
7744                 tempSet[i] = 0;
7745 
7746             fromI = toJ = everyK = -1;
7747             foundDash = foundSlash = NO;
7748             MrBayesPrint ("%s   Defining taxset called '%s'\n", spacer, tkn);
7749             expecting = Expecting(EQUALSIGN);
7750             }
7751         else
7752             return (ERROR);
7753         }
7754     else if (expecting == Expecting(EQUALSIGN))
7755         {
7756         expecting  = Expecting(ALPHA);
7757         expecting |= Expecting(NUMBER);
7758         }
7759     else if (expecting == Expecting(ALPHA))
7760         {
7761         /* We are defining a taxon set in terms of another (called tkn, here) or we are referring to
7762            the taxon name. We should be able to find tkn in the list of character set names or in the list
7763            of taxon names. If we cannot, then we have a problem and return an error. */
7764         if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
7765             {
7766             if (numTaxaSets < 1)
7767                 {
7768                 MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
7769                 return (ERROR);
7770                 }
7771             if (CheckString (taxaSetNames, numTaxaSets, tkn, &index) == ERROR)
7772                 {
7773                 MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
7774                 return (ERROR);
7775                 }
7776             /* add taxa from taxset tkn to new tempSet */
7777             for (i=0; i<numTaxa; i++)
7778                 {
7779                 if (IsBitSet (i, taxaSet[index]) == YES)
7780                     tempSet[i] = 1;
7781                 }
7782             }
7783         else
7784             {
7785             tempSet[index] = 1;
7786             }
7787         fromI = toJ = everyK = -1;
7788 
7789         expecting  = Expecting(ALPHA);
7790         expecting |= Expecting(NUMBER);
7791         expecting |= Expecting(SEMICOLON);
7792         }
7793     else if (expecting == Expecting(NUMBER))
7794         {
7795         if (strlen(tkn) == 1 && !strcmp(tkn, "."))
7796             {
7797             tempInt = numTaxa;
7798             }
7799         else
7800             {
7801             sscanf (tkn, "%d", &tempInt);
7802             if (tempInt <= 0 || tempInt > numTaxa)
7803                 {
7804                 MrBayesPrint ("%s   Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa);
7805                 return (ERROR);
7806                 }
7807             }
7808         tempInt--;
7809         if (foundDash == YES)
7810             {
7811             if (fromI >= 0)
7812                 toJ = tempInt;
7813             else
7814                 {
7815                 MrBayesPrint ("%s   Improperly formatted taxset\n", spacer);
7816                 return (ERROR);
7817                 }
7818             foundDash = NO;
7819             }
7820         else if (foundSlash == YES)
7821             {
7822             tempInt++;
7823             if (tempInt <= 1)
7824                 {
7825                 MrBayesPrint ("%s   Improperly formatted taxset\n", spacer);
7826                 return (ERROR);
7827                 }
7828             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
7829                 everyK = tempInt;
7830             else
7831                 {
7832                 MrBayesPrint ("%s   Improperly formatted taxset\n", spacer);
7833                 return (ERROR);
7834                 }
7835             foundSlash = NO;
7836             }
7837         else
7838             {
7839             if (fromI >= 0 && toJ < 0)
7840                 {
7841                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7842                     return (ERROR);
7843                 fromI = tempInt;
7844                 }
7845             else if (fromI < 0 && toJ < 0)
7846                 {
7847                 fromI = tempInt;
7848                 }
7849             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
7850                 {
7851                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7852                     return (ERROR);
7853                 fromI = tempInt;
7854                 toJ = everyK = -1;
7855                 }
7856             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
7857                 {
7858                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7859                     return (ERROR);
7860                 fromI = tempInt;
7861                 toJ = everyK = -1;
7862                 }
7863             else
7864                 {
7865                 MrBayesPrint ("%s   Improperly formatted taxset\n", spacer);
7866                     {
7867                     return (ERROR);
7868                     }
7869                 }
7870             }
7871 
7872         expecting  = Expecting(ALPHA);
7873         expecting |= Expecting(NUMBER);
7874         expecting |= Expecting(SEMICOLON);
7875         expecting |= Expecting(DASH);
7876         expecting |= Expecting(BACKSLASH);
7877         }
7878     else if (expecting == Expecting(DASH))
7879         {
7880         foundDash = YES;
7881         expecting = Expecting(NUMBER);
7882         }
7883     else if (expecting == Expecting(BACKSLASH))
7884         {
7885         foundSlash = YES;
7886         expecting = Expecting(NUMBER);
7887         }
7888     else
7889         return (ERROR);
7890 
7891     return (NO_ERROR);
7892 }
7893 
7894 
DoTaxaStat(void)7895 int DoTaxaStat (void)
7896 {
7897     int         i, j, maxLen, nameLen, nIncludedTaxa;
7898     char        tempName[100];
7899 
7900     if (defMatrix == NO)
7901         {
7902         MrBayesPrint ("%s   A character matrix must be defined first\n", spacer);
7903         return (ERROR);
7904         }
7905 
7906     /* find maximum length of taxon name */
7907     maxLen = nIncludedTaxa = 0;
7908     for (i=0; i<numTaxa; i++)
7909         {
7910         strcpy (tempName, taxaNames[i]);
7911         if ((int)strlen(tempName) > maxLen)
7912             maxLen = (int) strlen(tempName);
7913         if (taxaInfo[i].isDeleted == NO)
7914             nIncludedTaxa++;
7915         }
7916 
7917     MrBayesPrint ("%s   Showing taxon status:\n\n", spacer);
7918     if (nIncludedTaxa == numTaxa)
7919         MrBayesPrint ("%s     Number of taxa        = %d (all of which are included)\n", spacer, numTaxa);
7920     else
7921         MrBayesPrint ("%s     Number of taxa        = %d (of which %d are included)\n", spacer, numTaxa, nIncludedTaxa);
7922     MrBayesPrint ("%s     Number of constraints = %d\n\n", spacer, numDefinedConstraints);
7923 
7924     if (numDefinedConstraints > 0)
7925         {
7926         for (j=0; j<numDefinedConstraints; j++)
7927             {
7928             strcpy (tempName, constraintNames[j]);
7929 
7930             /* for now, ignore the probability */
7931             if (definedConstraintsType[j] == HARD)
7932                 MrBayesPrint ("%s     %2d -- Trees with 'hard' constraint \"%s\" are infinitely\n", spacer, j+1, tempName);
7933             else if (definedConstraintsType[j] == PARTIAL)
7934                 MrBayesPrint ("%s     %2d -- Trees with 'partial' constraint \"%s\" are infinitely\n", spacer, j+1, tempName);
7935             else
7936                 MrBayesPrint ("%s     %2d -- Trees with 'negative' constraint \"%s\" are infinitely\n", spacer, j+1, tempName);
7937             MrBayesPrint ("%s           more probable than those without \n", spacer);
7938             }
7939         MrBayesPrint ("\n");
7940         for (j=0; j<maxLen; j++)
7941             MrBayesPrint (" ");
7942         MrBayesPrint ("                             Constraints\n");
7943         }
7944     MrBayesPrint ("%s     Taxon  ", spacer);
7945     for (j=0; j<maxLen; j++)
7946         MrBayesPrint (" ");
7947     MrBayesPrint ("   Inclusion");
7948     MrBayesPrint ("   ");
7949     for (j=0; j<numDefinedConstraints; j++)
7950         MrBayesPrint (" %2d", j+1);
7951     MrBayesPrint ("\n");
7952     MrBayesPrint ("%s   -------", spacer);
7953     for (j=0; j<maxLen; j++)
7954         MrBayesPrint ("-");
7955     MrBayesPrint ("--------------");
7956 
7957     if (numDefinedConstraints > 0)
7958         {
7959         MrBayesPrint ("----");
7960         for (j=0; j<numDefinedConstraints; j++)
7961             MrBayesPrint ("---");
7962         }
7963     MrBayesPrint ("\n");
7964     for (i=0; i<numTaxa; i++)
7965         {
7966         strcpy (tempName, taxaNames[i]);
7967         nameLen = (int) strlen(tempName);
7968 
7969         if (i == outGroupNum)
7970             MrBayesPrint ("%s ->%4d (%s) ", spacer, i+1, tempName);
7971         else
7972             MrBayesPrint ("%s   %4d (%s) ", spacer, i+1, tempName);
7973         for (j=0; j<(maxLen-nameLen); j++)
7974             MrBayesPrint (" ");
7975         MrBayesPrint (" -- ");
7976 
7977         if (taxaInfo[i].isDeleted == YES)
7978             MrBayesPrint ("Deleted ");
7979         else
7980             MrBayesPrint ("Included");
7981 
7982         MrBayesPrint ("    ");
7983 
7984         for (j=0; j<numDefinedConstraints; j++)
7985             {
7986             if (definedConstraintsType[j] == HARD)
7987                 {
7988                 if (IsBitSet(i, definedConstraint[j]) == NO)
7989                     MrBayesPrint ("  .");
7990                 else
7991                     MrBayesPrint ("  *");
7992                 }
7993             else if (definedConstraintsType[j] == PARTIAL)
7994                 {
7995                 if (IsBitSet(i, definedConstraint[j]) == YES)
7996                     MrBayesPrint ("  +");
7997                 else if (IsBitSet(i, definedConstraintTwo[j]) == YES)
7998                     MrBayesPrint ("  -");
7999                 else
8000                     MrBayesPrint ("  .");
8001                 }
8002             else if (definedConstraintsType[j] == NEGATIVE)
8003                 {
8004                 if (IsBitSet(i, definedConstraint[j]) == NO)
8005                     MrBayesPrint ("  .");
8006                 else
8007                     MrBayesPrint ("  #");
8008                 }
8009             }
8010         MrBayesPrint ("\n");
8011         }
8012 
8013     MrBayesPrint ("\n");
8014     MrBayesPrint ("%s   '.' indicate that the taxon is not present in the constraint. \n", spacer);
8015     MrBayesPrint ("%s   '*' indicate that the taxon is present in the 'hard' constraint. \n", spacer);
8016     MrBayesPrint ("%s   '+' indicate that the taxon is present in the first groupe of 'partial' constraint. \n", spacer);
8017     MrBayesPrint ("%s   '-' indicate that the taxon is present in the second groupe of 'partial' constraint. \n", spacer);
8018     MrBayesPrint ("%s   '#' indicate that the taxon is present in the 'negative' constraint. \n", spacer);
8019     MrBayesPrint ("%s   Arrow indicates current outgroup. \n", spacer);
8020 
8021     return (NO_ERROR);
8022 }
8023 
8024 
DoTranslate(void)8025 int DoTranslate (void)
8026 {
8027     int     i, j;
8028 
8029     if (inTreesBlock == NO)
8030         {
8031         MrBayesPrint ("%s   You must be in a trees block to read a translate command\n", spacer);
8032         return (ERROR);
8033         }
8034     numTranslates++;    /* number of taxa in translate table */
8035     isTranslateDef = YES;
8036 
8037     isTranslateDiff = NO;
8038     if (isTaxsetDef == NO)
8039         SetTaxaFromTranslateTable();
8040     else
8041         {
8042         for (i=0; i<numTranslates; i++)
8043             {
8044             strcpy (token, transFrom[i]);
8045             if (CheckString (taxaNames, numTaxa, token, &j) == ERROR)
8046                 {
8047                 isTranslateDiff = YES;
8048                 }
8049             }
8050         if (numTranslates != numTaxa)
8051             isTranslateDiff = YES;
8052         }
8053 
8054     return (NO_ERROR);
8055 }
8056 
8057 
DoTranslateParm(char * parmName,char * tkn)8058 int DoTranslateParm (char *parmName, char *tkn)
8059 {
8060     int         index;
8061     static int  whichTranslate;
8062 
8063     if (inTreesBlock == NO)
8064         {
8065         MrBayesPrint ("%s   You must be in a trees block to read a translate command\n", spacer);
8066         return (ERROR);
8067         }
8068 
8069     if (isTranslateDef == YES)
8070         {
8071         MrBayesPrint ("%s   A translation has already been defined for this tree block\n", spacer);
8072         return (ERROR);
8073         }
8074 
8075     if (expecting == Expecting(ALPHA) ||
8076         expecting == Expecting(NUMBER))
8077         {
8078         if (numTaxa == 0)
8079             {
8080             MrBayesPrint ("%s   Data matrix should be defined before translation table could be set.\n", spacer);
8081             return (ERROR);
8082             }
8083         if (numTranslates == numTaxa)
8084             {
8085             MrBayesPrint ("%s   Too many entries in translation table. Maximum number of taxon names to translate is %d\n", spacer,numTaxa);
8086             return (ERROR);
8087             }
8088         if (whichTranslate == 0)
8089             {
8090             if (CheckString (transTo, numTranslates, tkn, &index) == ERROR)
8091                 {
8092                 if (AddString (&transTo, numTranslates, tkn) == ERROR)
8093                     {
8094                     MrBayesPrint ("%s   Problem adding taxon %s to list\n", spacer, tkn);
8095                     return (ERROR);
8096                     }
8097                 }
8098             else
8099                 {
8100                 MrBayesPrint ("%s   Already found name (%s) in list\n", spacer, tkn);
8101                 return (ERROR);
8102                 }
8103             whichTranslate++;
8104             expecting = Expecting(ALPHA);
8105             expecting |= Expecting(NUMBER);
8106             }
8107         else
8108             {
8109             if (CheckString (transFrom, numTranslates, tkn, &index) == ERROR)
8110                 {
8111                 if (AddString (&transFrom, numTranslates, tkn) == ERROR)
8112                     {
8113                     MrBayesPrint ("%s   Problem adding taxon %s to list\n", spacer, tkn);
8114                     return (ERROR);
8115                     }
8116                 }
8117             else
8118                 {
8119                 MrBayesPrint ("%s   Already found name (%s) in list\n", spacer, tkn);
8120                 return (ERROR);
8121                 }
8122             whichTranslate = 0;
8123             expecting = Expecting(COMMA);
8124             expecting |= Expecting(SEMICOLON);
8125             }
8126         }
8127     else if (expecting == Expecting(COMMA))
8128         {
8129         numTranslates++;
8130         expecting = Expecting(ALPHA);
8131         expecting |= Expecting(NUMBER);
8132         }
8133 
8134     return (NO_ERROR);
8135 }
8136 
8137 
DoTree(void)8138 int DoTree (void)
8139 {
8140     readComment = NO;
8141 
8142     if (inSumtCommand == YES || inComparetreeCommand == YES)
8143         return (DoSumtTree ());
8144 
8145     return (NO_ERROR);
8146 }
8147 
8148 
DoTreeParm(char * parmName,char * tkn)8149 int DoTreeParm (char *parmName, char *tkn)
8150 {
8151     int                 i, tempInt, index;
8152     MrBFlt              tempD;
8153     char                tempName[100];
8154     static BitsLong     lastExpecting; /* keep track of what we expected before a comment, in case we want to skip a comment */
8155     static char         *tempNameString=NULL; /* Contains multiple tokens which form name string of param set*/
8156     static int          foundAmpersand, foundColon, foundComment, foundE, foundB, foundN, foundFirst,
8157                         foundCurly, /* is set to YES when we are between two curly bracets ONLY while processing CppEvent name */
8158                         foundClockrate,
8159                         foundName, /*is set to YES when param set name token is found and set to NO once full param set name is processed*/
8160                         eSetIndex, /* is set in the begining of reading CppEvent for a node/branch to the index of currently processed CppEvent set */
8161                         bSetIndex, eventIndex, treeIndex, nextIntNodeIndex;
8162     static PolyNode     *pp, *qq;
8163     static PolyTree     *t;
8164 
8165     /* This function will read in components of a tree description. We expect one of the following formats:
8166 
8167           tree <name> = [&R] <newick-description>;
8168           tree <name> = [&U] <newick-description>;
8169           tree <name> [&E CppEvents]  = [&R] [&clockrate = 1.23] ((1:0.021[&E CppEvents 2: (0.10 1.11,0.83 3.17)],...
8170           tree <name> [&B TK02Brlens] = [&R] [&clockrate = 1.23] ((1:0.021[&B TK02Brlens 0.019],...
8171           tree <name> [&B IgrBrlens]  = [&R] [&clockrate = 1.23] ((1:0.021[&B IgrBrlens 0.019],...
8172 
8173        Values will be stored in event sets that go with the tree and that are used to initialize the relaxed clock
8174        parameters before a run is started. Note that several sets of events can be stored with each tree.
8175     */
8176 
8177     if (isTaxsetDef == NO)
8178         {
8179         MrBayesPrint ("%s   Taxon labels must be specified before a tree could be red in\n", spacer);
8180         return (ERROR);
8181         }
8182     if (inTreesBlock == NO)
8183         {
8184         MrBayesPrint ("%s   You must be in a trees block to read a tree\n", spacer);
8185         return (ERROR);
8186         }
8187 
8188     if (expecting == Expecting(PARAMETER))
8189         {
8190         /* this is the name of the tree */
8191         if (inSumtCommand==YES || inComparetreeCommand == YES)
8192             {
8193             /* we are reading in a tree to sumt or comparetree counters */
8194             t = sumtParams.tree;
8195             ResetPolyTree (t);
8196             }
8197         else
8198             {
8199             /* we are reading in a user tree */
8200             /* check if the tree exists */
8201             treeIndex = 0;
8202             for (i=0; i<numUserTrees; i++)
8203                 if (strcmp(tkn,userTree[i]->name) == 0)
8204                     break;
8205             treeIndex = i;
8206             if (treeIndex < numUserTrees)
8207                 {
8208                 MrBayesPrint ("%s   Overwriting tree '%s'.\n", spacer, userTree[treeIndex]);
8209                 FreePolyTree (userTree[treeIndex]);
8210                 }
8211             if ((userTree[treeIndex] = AllocatePolyTree (numTaxa)) == NULL)
8212                 return (ERROR);
8213             t = userTree[treeIndex];
8214             }
8215         strncpy (t->name, tkn, 99);
8216         foundColon = foundAmpersand = foundEqual = foundComment = NO;
8217         foundE = foundB = foundN = foundFirst = foundClockrate = foundName = NO;
8218         eSetIndex = bSetIndex = eventIndex = 0;
8219         nextAvailableNode = 0;
8220         if (isTranslateDef == YES && isTranslateDiff == YES)
8221             nextIntNodeIndex = numTranslates;
8222         else
8223             nextIntNodeIndex = numTaxa;
8224         pp = &t->nodes[nextAvailableNode++];
8225         t->root = pp;
8226         t->isRooted = NO;  /* expect unrooted tree */
8227         t->isClock = NO;   /* expect nonclock tree */
8228         t->isCalibrated = NO;  /* expect uncalibrated tree */
8229         t->isRelaxed = NO;    /* expect strict clock if clock tree */
8230         t->clockRate = 0.0;     /* expect no clock rate */
8231         t->popSizeSet = NO;
8232         readComment = YES;
8233         expecting = Expecting(EQUALSIGN) | Expecting(LEFTCOMMENT);
8234         lastExpecting = expecting;
8235         }
8236     else if (expecting == Expecting(EQUALSIGN))
8237         {
8238         if (foundClockrate == YES)
8239             expecting = Expecting(NUMBER);
8240         else
8241             {
8242             for (i=0; i<numTaxa; i++)
8243                 tempSet[i] = NO;
8244             foundEqual = YES;
8245             expecting = Expecting(LEFTPAR) | Expecting(LEFTCOMMENT);
8246             lastExpecting = expecting;
8247             }
8248         }
8249     else if (expecting == Expecting(LEFTPAR))
8250         {
8251         if (foundE == YES)
8252             {
8253             expecting = Expecting(NUMBER);
8254             }
8255         else
8256             {
8257             if (nextAvailableNode >= 2*numTaxa)
8258                 {
8259                 MrBayesPrint ("%s   Too many nodes on tree '%s'\n", spacer, t->name);
8260                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8261                     FreePolyTree (userTree[treeIndex]);
8262                 return (ERROR);
8263                 }
8264             /* FIXME: t == NULL here (from clang static analyzer) */
8265             qq = &t->nodes[nextAvailableNode++];
8266             qq->anc = pp;
8267             pp->left = qq;
8268             pp->index = nextIntNodeIndex++;
8269             pp = qq;
8270             expecting = Expecting(LEFTPAR);
8271             expecting |= Expecting(ALPHA);
8272             expecting |= Expecting(NUMBER);
8273             expecting |= Expecting(LEFTCOMMENT);
8274             lastExpecting = expecting;
8275             }
8276         }
8277     else if (expecting == Expecting(ALPHA))
8278         {
8279         if (foundAmpersand == YES)
8280             {
8281             if (strcmp(tkn,"E") == 0)
8282                 {
8283                 foundE = YES;
8284                 expecting = Expecting(ALPHA);
8285                 }
8286             else if (strcmp(tkn,"B") == 0)
8287                 {
8288                 foundB = YES;
8289                 expecting = Expecting(ALPHA);
8290                 }
8291             else if (strcmp(tkn,"N") == 0)
8292                 {
8293                 foundN = YES;
8294                 expecting = Expecting(ALPHA);
8295                 }
8296             else if (strcmp(tkn, "R") == 0)
8297                 {
8298                 t->isRooted = YES;
8299                 t->isClock = YES;   /* assume clock if rooted */
8300                 expecting = Expecting(RIGHTCOMMENT);
8301                 }
8302             else if (strcmp(tkn, "U") == 0)
8303                 {
8304                 t->isRooted = NO;
8305                 expecting = Expecting(RIGHTCOMMENT);
8306                 }
8307             else if (strcmp(tkn, "clockrate") == 0)
8308                 {
8309                 t->isCalibrated = YES;
8310                 foundClockrate = YES;
8311                 expecting = Expecting(EQUALSIGN);
8312                 }
8313             else
8314                 {
8315                 inComment = YES;
8316                 numComments++;
8317                 expecting = lastExpecting;
8318                 }
8319             foundAmpersand = NO;
8320             }
8321         else if (foundName == YES && foundCurly == YES)
8322             {
8323             if (strcmp("all",tkn) == 0)
8324                 {
8325                 SafeStrcat (&tempNameString,tkn);
8326                 expecting = Expecting(RIGHTCURL);
8327                 }
8328             else
8329                 {
8330                 MrBayesPrint ("%s   Urecognized argument '%s'\n", spacer, tkn);
8331                 return (ERROR);
8332                 }
8333             }
8334         else if (foundE == YES) /* We have seen &E */
8335             {
8336             if (foundEqual == NO) /* We have not seen name before and we are in header */
8337                 {
8338                 t->nESets++;
8339                 t->isRelaxed = YES;
8340                 t->nEvents  = (int **) SafeRealloc ((void *)t->nEvents, t->nESets*sizeof(int *));
8341                 t->position = (MrBFlt ***) SafeRealloc ((void *)t->position, t->nESets*sizeof(MrBFlt **));
8342                 t->rateMult = (MrBFlt ***) SafeRealloc ((void *)t->rateMult, t->nESets*sizeof(MrBFlt **));
8343                 t->nEvents[t->nESets-1]  = (int *) SafeCalloc (2*(size_t)numTaxa, sizeof(int));
8344                 t->position[t->nESets-1] = (MrBFlt **) SafeCalloc (2*(size_t)numTaxa, sizeof(MrBFlt *));
8345                 t->rateMult[t->nESets-1] = (MrBFlt **) SafeCalloc (2*(size_t)numTaxa, sizeof(MrBFlt *));
8346                 t->eSetName = (char **) SafeRealloc ((void *)t->eSetName, t->nESets*sizeof(char **));
8347                 }
8348             SafeStrcpy (&tempNameString,tkn);
8349             foundName = YES;
8350             expecting = Expecting(LEFTCURL);
8351             if (foundEqual == YES)
8352                 expecting |= Expecting(NUMBER);
8353             else
8354                 expecting |= Expecting(RIGHTCOMMENT);
8355             }
8356         else if (foundB == YES)
8357             {
8358             if (foundEqual == NO)
8359                 {
8360                 t->nBSets++;
8361                 t->isRelaxed = YES;
8362                 t->effectiveBrLen = (MrBFlt **) SafeRealloc ((void *)t->effectiveBrLen, (size_t)(t->nBSets)*sizeof(MrBFlt *));
8363                 t->effectiveBrLen[t->nBSets-1] = (MrBFlt *) SafeCalloc (2*(size_t)numTaxa, sizeof(MrBFlt));
8364                 for (i=0; i<2*numTaxa; i++)
8365                     t->effectiveBrLen[t->nBSets-1][i] = 1.0;
8366                 t->bSetName = (char **) SafeRealloc ((void *)t->bSetName, (size_t)(t->nBSets)*sizeof(char *));
8367                 t->bSetName[t->nBSets-1] = (char *) SafeCalloc (strlen(tkn)+1, sizeof(char));
8368                 }
8369             SafeStrcpy (&tempNameString,tkn);
8370             foundName = YES;
8371             expecting = Expecting(LEFTCURL);
8372             if (foundEqual == YES)
8373                 expecting |= Expecting(NUMBER);
8374             else
8375                 expecting |= Expecting(RIGHTCOMMENT);
8376             }
8377         else if (foundN == YES)
8378             {
8379             if (foundEqual == NO)
8380                 {
8381                 if (t->popSizeSet == YES)
8382                     {
8383                     MrBayesPrint ("%s   Cannot hold more than one population size set\n", spacer);
8384                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8385                         FreePolyTree (userTree[treeIndex]);
8386                     return (ERROR);
8387                     }
8388                 t->popSizeSet = YES;
8389                 if (isTranslateDef == YES && isTranslateDiff == YES)
8390                     t->popSize = (MrBFlt *) SafeCalloc (2*numTranslates, sizeof(MrBFlt));
8391                 else
8392                     t->popSize = (MrBFlt *) SafeCalloc (2*numLocalTaxa, sizeof(MrBFlt));
8393                 }
8394             SafeStrcpy (&tempNameString,tkn);
8395             foundName = YES;
8396             expecting = Expecting(LEFTCURL);
8397             if (foundEqual == YES)
8398                 expecting |= Expecting(NUMBER);
8399             else
8400                 expecting |= Expecting(RIGHTCOMMENT);
8401             }
8402         else   /* taxon name */
8403             {
8404             if (isTranslateDef == YES)
8405                 {
8406                 /* we are using the translation table */
8407                 if (CheckString (transTo, numTranslates, tkn, &index) == ERROR)
8408                     {
8409                     MrBayesPrint ("%s   Could not find token '%s' in taxon translation table\n", spacer, tkn);
8410                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8411                         FreePolyTree (userTree[treeIndex]);
8412                     return (ERROR);
8413                     }
8414                 strcpy (tempName, transFrom[index]);
8415                 if (isTranslateDiff == NO && CheckString (taxaNames, numTaxa, tempName, &index) == ERROR)
8416                     {
8417                     MrBayesPrint ("%s   Could not find taxon '%s' in list of taxa\n", spacer, tkn);
8418                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8419                         FreePolyTree (userTree[treeIndex]);
8420                     return (ERROR);
8421                     }
8422                 if (tempSet[index] == YES)
8423                     {
8424                     MrBayesPrint ("%s   Taxon name '%s' already used in tree\n", spacer, tkn);
8425                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8426                         FreePolyTree (userTree[treeIndex]);
8427                     return (ERROR);
8428                     }
8429                 tempSet[index] = YES;
8430                 /* FIXME: pp is NULL here (from clang static analyzer) */
8431                 strcpy (pp->label, tempName);
8432                 pp->index = index;
8433                 }
8434             else
8435                 {
8436                 /* Check to see if the name is in the list of taxon names. */
8437                 if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
8438                     {
8439                     MrBayesPrint ("%s   Could not find taxon '%s' in list of taxa\n", spacer, tkn);
8440                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8441                         FreePolyTree (userTree[treeIndex]);
8442                     return (ERROR);
8443                     }
8444                 if (tempSet[index] == YES)
8445                     {
8446                     MrBayesPrint ("%s   Taxon name '%s' already used in tree\n", spacer, tkn);
8447                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8448                         FreePolyTree (userTree[treeIndex]);
8449                     return (ERROR);
8450                     }
8451                 tempSet[index] = YES;
8452                 /* FIXME: pp is NULL here (from clang static analyzer) */
8453                 strcpy (pp->label, tkn);
8454                 pp->index = index;
8455                 }
8456             expecting  = Expecting(COMMA);
8457             expecting |= Expecting(COLON);
8458             expecting |= Expecting(RIGHTPAR);
8459             }
8460         }
8461     else if (expecting == Expecting(RIGHTPAR))
8462         {
8463         if (foundE == YES)
8464             expecting = Expecting(RIGHTCOMMENT);
8465         else
8466             {
8467             if (pp->anc == NULL)
8468                 {
8469                 MrBayesPrint ("%s   Incorrect tree format: cannot go down\n", spacer);//, tkn
8470                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8471                     FreePolyTree (userTree[treeIndex]);
8472                 return (ERROR);
8473                 }
8474             if (pp->anc->left == pp)
8475                 {
8476                 MrBayesPrint ("%s   Incorrect tree format: all nodes except tips should have more then one child. Either a single\n", spacer);
8477                 MrBayesPrint ("%s   taxon is surrounded with brackets or there is a clade surrounded by double brackets.\n", spacer);
8478                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8479                     FreePolyTree (userTree[treeIndex]);
8480                 return (ERROR);
8481                 }
8482             pp = pp->anc;
8483             if (pp->anc == NULL)
8484                 {
8485                 /* finish up tree */
8486                 t->nNodes = nextAvailableNode;
8487                 t->nIntNodes = t->nNodes;
8488                 for (i=0; i<t->nNodes; i++)
8489                     {
8490                     if (t->nodes[i].left == NULL)
8491                         t->nIntNodes--;
8492                     }
8493                 GetPolyDownPass(t);
8494 
8495                 /* check that number of taxa is correct */
8496                 if (t->isRooted == NO && t->nNodes-t->nIntNodes == t->nIntNodes + 1)
8497                     t->isRooted = YES;
8498                 if ((t->isRooted == YES && t->nNodes-t->nIntNodes != t->nIntNodes + 1) ||
8499                     (t->isRooted == NO  && t->nNodes-t->nIntNodes != t->nIntNodes + 2))
8500                     {
8501                     /* we are protected from adding too many taxa by taxon-matching code above */
8502                     if (t->isRooted == YES && t->nNodes-t->nIntNodes == t->nIntNodes + 2)
8503                         {
8504                         MrBayesPrint ("%s   The tree is declared as rooted (by comment [&R]) but\n", spacer);
8505                         MrBayesPrint ("%s   the given tree has unrooted structure.\n", spacer);
8506                         }
8507                     else
8508                         MrBayesPrint ("%s   Taxa missing in tree, or NOT a binary tree\n", spacer);
8509 
8510                     return (ERROR);
8511                     }
8512 
8513                 /* check other properties */
8514                 if (t->isClock == YES && t->isRooted == NO)
8515                     {
8516                     MrBayesPrint ("%s   Tree has clock rate but is not rooted\n", spacer);
8517                     return (ERROR);
8518                     /* Note: any deviation from an ultrametric tree must be assumed to be due to dated
8519                        tips at this point */
8520                     }
8521                 if (t->isRelaxed == YES && t->isClock == NO)
8522                     {
8523                     MrBayesPrint ("%s   Tree has relaxed clock rates but is not a clock tree\n", spacer);
8524                     return (ERROR);
8525                     }
8526                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8527                     {
8528                     if (treeIndex == numUserTrees)
8529                         numUserTrees++;
8530                     MrBayesPrint ("%s   Successfully read tree '%s'\n", spacer, userTree[treeIndex]->name);
8531                     }
8532                 if (t->popSize == NULL)
8533                     {
8534                     readComment = NO;
8535                     expecting = Expecting(SEMICOLON);
8536                     }
8537                 else
8538                     {
8539                     readComment = YES;
8540                     expecting = Expecting(LEFTCOMMENT);
8541                     lastExpecting = expecting;
8542                     }
8543                 }
8544             else
8545                 {
8546                 expecting = Expecting(COMMA);
8547                 expecting |= Expecting(COLON);
8548                 expecting |= Expecting(RIGHTPAR);
8549                 }
8550             }
8551         }
8552     else if (expecting == Expecting(COLON))
8553         {
8554         foundColon = YES;
8555         if (foundE == YES)
8556             expecting = Expecting(LEFTPAR);
8557         else
8558             expecting  = Expecting(NUMBER);
8559         expecting |= Expecting(LEFTCOMMENT);
8560         lastExpecting = expecting;
8561         }
8562     else if (expecting == Expecting(COMMA))
8563         {
8564         if (foundName == YES)
8565             {
8566             SafeStrcat (&tempNameString,",");
8567             expecting = Expecting(NUMBER);
8568             }
8569         else if (foundE == YES)
8570             {
8571             expecting = Expecting(NUMBER);
8572             }
8573         else
8574             {
8575             if (nextAvailableNode >= 2*numTaxa)
8576                 {
8577                 MrBayesPrint ("%s   Too many nodes on tree '%s'\n", spacer, t->name);
8578                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8579                     FreePolyTree (userTree[treeIndex]);
8580                 return (ERROR);
8581                 }
8582             /* FIXME: t is NULL here (from clang static analyzer) */
8583             qq = &t->nodes[nextAvailableNode++];
8584             pp->sib = qq;
8585             qq->anc = pp->anc;
8586             pp = qq;
8587             expecting = Expecting(LEFTPAR);
8588             expecting |= Expecting(ALPHA);
8589             expecting |= Expecting(NUMBER);
8590             expecting |= Expecting(LEFTCOMMENT);
8591             lastExpecting = expecting;
8592             }
8593         }
8594     else if (expecting == Expecting(NUMBER))
8595         {
8596         if (foundClockrate == YES)
8597             {
8598             sscanf (tkn, "%lf", &tempD);
8599             t->clockRate = tempD;
8600             foundClockrate = NO;
8601             expecting = Expecting(RIGHTCOMMENT);
8602             }
8603         else if (foundName == YES && foundCurly == YES)
8604             {
8605             /* still assembling name of a param set */
8606             SafeStrcat (&tempNameString,tkn);
8607             expecting = Expecting(RIGHTCURL) | Expecting(COMMA);
8608             }
8609         else if (foundN == YES)
8610             {
8611             /* we only know now that name is complete if it does not have curlies in it */
8612             foundName = NO;
8613 
8614             if (strcmp(tempNameString,t->popSizeSetName) != 0)
8615                 {
8616                 MrBayesPrint ("%s   Could not find population size set '%s'\n", spacer, tempNameString);
8617                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8618                     FreePolyTree (userTree[treeIndex]);
8619                 return (ERROR);
8620                 }
8621 
8622             sscanf (tkn, "%lf", &tempD);
8623             t->popSize[pp->index] = tempD;
8624             foundN = NO;
8625             expecting = Expecting(RIGHTCOMMENT);
8626             }
8627         else if (foundB == YES)
8628             {
8629             /* we only know now that name is complete if it does not have curlies in it */
8630             foundName = NO;
8631 
8632             /* find the right effective branch length set */
8633             for (i=0; i<t->nBSets; i++)
8634                 if (strcmp(t->bSetName[i],tempNameString) == 0)
8635                     break;
8636             if (i == t->nBSets)
8637                 {
8638                 MrBayesPrint ("%s   Could not find effective branch length set '%s'\n", spacer, tempNameString);
8639                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8640                     FreePolyTree (userTree[treeIndex]);
8641                 return (ERROR);
8642                 }
8643             bSetIndex = i;
8644 
8645             sscanf (tkn, "%lf", &tempD);
8646             t->effectiveBrLen[bSetIndex][pp->index] = tempD;
8647             foundB = NO;
8648             expecting = Expecting(RIGHTCOMMENT);
8649             }
8650         else if (foundE == YES)
8651             {
8652             if (foundColon == NO)
8653                 {
8654                 /* we only know now that name is complete if it does not have curlies in it */
8655                 foundName = NO;
8656 
8657                 /* find the right event set */
8658                 for (i=0; i<t->nESets; i++)
8659                     if (strcmp(t->eSetName[i],tempNameString) == 0)
8660                         break;
8661                 if (i == t->nESets)
8662                     {
8663                     MrBayesPrint ("%s   Could not find event set '%s'\n", spacer, tempNameString);
8664                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8665                         FreePolyTree (userTree[treeIndex]);
8666                     return (ERROR);
8667                     }
8668                 eSetIndex = i;
8669 
8670                 sscanf (tkn, "%d", &tempInt);
8671                 if (tempInt < 0)
8672                     {
8673                     MrBayesPrint ("%s   Wrong number of events (%d) for event set '%s'\n", spacer, tempInt, t->eSetName[eSetIndex]);
8674                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8675                         FreePolyTree (userTree[treeIndex]);
8676                     return (ERROR);
8677                     }
8678                 t->nEvents[eSetIndex][pp->index]  = tempInt;
8679                 if (tempInt > 0)
8680                     {
8681                     t->position[eSetIndex][pp->index] = (MrBFlt *) SafeCalloc (tempInt, sizeof(MrBFlt));
8682                     t->rateMult[eSetIndex][pp->index] = (MrBFlt *) SafeCalloc (tempInt, sizeof(MrBFlt));
8683                     expecting = Expecting (COLON);
8684                     if (inSumtCommand == YES || inComparetreeCommand == YES)
8685                         expecting |= Expecting (RIGHTCOMMENT);  /* we allow empty event specifications in sumt and comparetree */
8686                     }
8687                 else
8688                     expecting = Expecting (RIGHTCOMMENT);
8689                 eventIndex = 0;
8690                 }
8691             else if (foundFirst == NO)
8692                 {
8693                 /* processing the first number in the cpp event pair <position rate> */
8694                 sscanf (tkn, "%lf", &tempD);
8695                 t->position[eSetIndex][pp->index][eventIndex] = tempD;
8696                 expecting = Expecting(NUMBER);
8697                 foundFirst = YES;
8698                 }
8699             else
8700                 {
8701                 /* processing the second number in the cpp event pair <position rate> */
8702                 foundFirst = NO;
8703                 sscanf (tkn, "%lf", &tempD);
8704                 t->rateMult[eSetIndex][pp->index][eventIndex] = tempD;
8705                 eventIndex++;
8706                 if (eventIndex == t->nEvents[eSetIndex][pp->index])
8707                     {
8708                     expecting = Expecting(RIGHTPAR);
8709                     foundColon = NO;
8710                     }
8711                 else
8712                     expecting = Expecting(COMMA);
8713                 }
8714             }
8715         else if (foundColon == YES)
8716             {
8717             /* branch length */
8718             sscanf (tkn, "%lf", &tempD);
8719             pp->length = tempD;
8720             foundColon = NO;
8721             t->brlensDef = YES;
8722             expecting  = Expecting(COMMA);
8723             expecting |= Expecting(RIGHTPAR);
8724             expecting |= Expecting(LEFTCOMMENT);
8725             lastExpecting = expecting;
8726             }
8727         else    /* taxon identifier */
8728             {
8729             if (isTranslateDef == YES)
8730                 {
8731                 /* we are using the translation table */
8732                 if (CheckString (transTo, numTranslates, tkn, &index) == ERROR)
8733                     {
8734                     MrBayesPrint ("%s   Could not find token '%s' in taxon translation table\n", spacer, tkn);
8735                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8736                         FreePolyTree (userTree[treeIndex]);
8737                     return (ERROR);
8738                     }
8739                 strcpy (tempName, transFrom[index]);
8740                 if (isTranslateDiff == NO && CheckString (taxaNames, numTaxa, tempName, &index) == ERROR)
8741                     {
8742                     MrBayesPrint ("%s   Could not find taxon '%s' in list of taxa\n", spacer, tkn);
8743                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8744                         FreePolyTree (userTree[treeIndex]);
8745                     return (ERROR);
8746                     }
8747                 if (tempSet[index] == YES)
8748                     {
8749                     MrBayesPrint ("%s   Taxon name '%s' already used in tree\n", spacer, tkn);
8750                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8751                         FreePolyTree (userTree[treeIndex]);
8752                     return (ERROR);
8753                     }
8754                 tempSet[index] = YES;
8755                 /* FIXME: pp is NULL here (from clang static analyzer) */
8756                 strcpy (pp->label, tempName);
8757                 pp->index = index;
8758                 }
8759             else
8760                 {
8761                 /* Simply use taxon number; first check to see if the name is in the list of taxon names. */
8762                 if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
8763                     {
8764                     /* The number could not be found as a taxon name in the list of taxon names. We will
8765                         assume that the user has then input taxa as numbers and not the names. */
8766                     sscanf (tkn, "%d", &index);
8767                     if (index < 1 || index > numTaxa)
8768                         {
8769                         MrBayesPrint ("%s   Taxon number %d is out of range\n", spacer, index);
8770                         if (inSumtCommand == NO && inComparetreeCommand == NO)
8771                             FreePolyTree (userTree[treeIndex]);
8772                         return (ERROR);
8773                         }
8774                     index--;
8775                     if (tempSet[index] == YES)
8776                         {
8777                         MrBayesPrint ("%s   Taxon name %d has already been used in tree '%s'\n", spacer, index+1, t->name);
8778                         if (inSumtCommand == NO && inComparetreeCommand == NO)
8779                             FreePolyTree (userTree[treeIndex]);
8780                         return (ERROR);
8781                         }
8782                     }
8783                 else
8784                     {
8785                     /* The number is in the list of taxon names */
8786                     if (index < 0 || index >= numTaxa)
8787                         {
8788                         MrBayesPrint ("%s   Taxon name %s could not be found\n", spacer, tkn);
8789                         if (inSumtCommand == NO && inComparetreeCommand == NO)
8790                             FreePolyTree (userTree[treeIndex]);
8791                         return (ERROR);
8792                         }
8793                     if (tempSet[index] == YES)
8794                         {
8795                         MrBayesPrint ("%s   Taxon %d has already been used in tree '%s'\n", spacer, index+1, t->name);
8796                         if (inSumtCommand == NO && inComparetreeCommand == NO)
8797                             FreePolyTree (userTree[treeIndex]);
8798                         return (ERROR);
8799                         }
8800                     }
8801                 tempSet[index] = YES;
8802                 /* FIXME: pp is NULL here (from clang static analyzer) */
8803                 strcpy (pp->label, taxaNames[index]);
8804                 pp->index = index;
8805                 }
8806             expecting  = Expecting(COMMA);
8807             expecting |= Expecting(COLON);
8808             expecting |= Expecting(RIGHTPAR);
8809             expecting |= Expecting(LEFTCOMMENT);
8810             lastExpecting = expecting;
8811             }
8812         }
8813     else if (expecting == Expecting(LEFTCOMMENT))
8814         {
8815         expecting = Expecting(AMPERSAND);
8816         foundComment = YES;
8817         }
8818     else if (expecting == Expecting(RIGHTCOMMENT))
8819         {
8820         if (foundEqual == NO)
8821             {
8822             /* We may have a complete name of a set of branch parameters, which needs to be recorded */
8823             if (foundName == YES)
8824                 {
8825                 if (foundE == YES)
8826                     {
8827                     t->eSetName[t->nESets-1] = (char *) SafeCalloc (strlen(tempNameString)+1,sizeof(char));
8828                     strcat(t->eSetName[t->nESets-1],tempNameString);
8829                     }
8830                 else if (foundB == YES)
8831                     {
8832                     t->bSetName[t->nBSets-1] = (char *) SafeCalloc (strlen(tempNameString)+1,sizeof(char));
8833                     strcat(t->bSetName[t->nBSets-1],tempNameString);
8834                     }
8835                 else if (foundN == YES)
8836                     {
8837                     t->popSizeSetName = (char *) SafeCalloc (strlen(tempNameString)+1,sizeof(char));
8838                     strcpy(t->popSizeSetName,tempNameString);
8839                     }
8840                 foundName = NO;
8841                 }
8842             expecting = Expecting(EQUALSIGN);
8843             }
8844         else
8845             {
8846             /* FIXME: pp is NULL here (from clang static analyzer) */
8847             if (pp->anc == NULL)
8848                 {
8849                 if (pp->left == NULL)
8850                     expecting = Expecting(LEFTPAR);
8851                 else
8852                     expecting = Expecting(SEMICOLON);
8853                 }
8854             else if (pp == pp->anc->left)
8855                 expecting = Expecting(COMMA);
8856             else
8857                 expecting = Expecting(RIGHTPAR);
8858             }
8859         foundE = foundB = foundN = NO;
8860         expecting |= Expecting(LEFTCOMMENT);
8861         }
8862     else if (expecting == Expecting(AMPERSAND))
8863         {
8864         foundAmpersand = YES;
8865         foundComment = NO;
8866         expecting = Expecting (ALPHA);
8867         }
8868     else if (foundComment == YES)
8869         {
8870         numComments++;
8871         foundComment = NO;
8872         }
8873     else if (expecting == Expecting(LEFTCURL))
8874         {
8875         if (foundName == YES)
8876             {
8877             foundCurly=YES;
8878             SafeStrcat (&tempNameString,"{");
8879             expecting = Expecting(NUMBER) | Expecting(ALPHA);
8880             }
8881         else
8882             return(ERROR);
8883         }
8884     else if (expecting == Expecting(RIGHTCURL))
8885         {
8886         if (foundName == YES)
8887             {
8888             SafeStrcat (&tempNameString,"}");
8889             foundCurly=NO;
8890             if (foundEqual == NO)
8891                 {
8892                 /* We are processing a name of a set of branch params in the header of a tree.  */
8893                 expecting = Expecting(RIGHTCOMMENT);
8894                 }
8895             else
8896                 {
8897                 /* We are processing a param value of a branch param set  */
8898                 expecting = Expecting(NUMBER);
8899                 }
8900             }
8901         else
8902             return(ERROR);
8903         }
8904 
8905     return (NO_ERROR);
8906 }
8907 
8908 
DoUserTree(void)8909 int DoUserTree (void)
8910 {
8911     MrBayesPrint ("%s   Usertree command deprecated. Define the tree in a treeblock and use 'Startvals' instead.\n", spacer);
8912     return (ERROR);
8913 }
8914 
8915 
DoUserTreeParm(char * parmName,char * tkn)8916 int DoUserTreeParm (char *parmName, char *tkn)
8917 {
8918     if (expecting == Expecting(EQUALSIGN))
8919         {
8920         expecting = Expecting(LEFTPAR);
8921         expecting |= Expecting(RIGHTPAR);
8922         expecting |= Expecting(COLON);
8923         expecting |= Expecting(NUMBER);
8924         expecting |= Expecting(ALPHA);
8925         expecting |= Expecting(SEMICOLON);
8926         }
8927     else if (expecting == Expecting(LEFTPAR))
8928         {
8929         expecting = Expecting(LEFTPAR);
8930         expecting |= Expecting(ALPHA);
8931         expecting |= Expecting(NUMBER);
8932         }
8933     else if (expecting == Expecting(ALPHA))
8934         {
8935         expecting = Expecting(COLON);
8936         expecting |= Expecting(COMMA);
8937         expecting |= Expecting(RIGHTPAR);
8938         }
8939     else if (expecting == Expecting(NUMBER))
8940         {
8941         expecting = Expecting(COLON);
8942         expecting |= Expecting(COMMA);
8943         expecting |= Expecting(RIGHTPAR);
8944         }
8945     else if (expecting == Expecting(COLON))
8946         {
8947         expecting = Expecting(NUMBER);
8948         }
8949     else if (expecting == Expecting(COMMA))
8950         {
8951         expecting = Expecting(LEFTPAR);
8952         expecting |= Expecting(ALPHA);
8953         expecting |= Expecting(NUMBER);
8954         }
8955     else if (expecting == Expecting(RIGHTPAR))
8956         {
8957         expecting = Expecting(RIGHTPAR);
8958         expecting |= Expecting(COMMA);
8959         expecting |= Expecting(COLON);
8960         expecting |= Expecting(SEMICOLON);
8961         }
8962     else
8963         return (ERROR);
8964 
8965     return (NO_ERROR);
8966 }
8967 
DoVersion(void)8968 int DoVersion (void)
8969 {
8970     MrBayesPrint ("   ---------------------------------------------------------------------------\n");
8971     MrBayesPrint ("   Version\n");
8972     MrBayesPrint ("\n");
8973     MrBayesPrint ("   MrBayes %s\n", VERSION_NUMBER);
8974     MrBayesPrint("\n");
8975     MrBayesPrint("   Features: ");
8976 #ifdef SSE_ENABLED
8977     MrBayesPrint(" SSE");
8978 #endif
8979 #ifdef AVX_ENABLED
8980     MrBayesPrint(" AVX");
8981 #endif
8982 #ifdef FMA_ENABLED
8983     MrBayesPrint(" FMA");
8984 #endif
8985 #ifdef BEAGLE_ENABLED
8986     MrBayesPrint(" Beagle");
8987 #endif
8988 #ifdef MPI_ENABLED
8989     MrBayesPrint(" MPI");
8990 #endif
8991 #ifdef HAVE_LIBREADLINE
8992     MrBayesPrint(" readline");
8993 #endif
8994     MrBayesPrint("\n");
8995 #if defined(HOST_TYPE) && defined(HOST_CPU)
8996     MrBayesPrint("   Host type: %s (CPU: %s)\n", HOST_TYPE, HOST_CPU);
8997 #endif
8998 #if defined(COMPILER_VENDOR) && defined(COMPILER_VERSION)
8999     MrBayesPrint("   Compiler:  %s %s\n", COMPILER_VENDOR, COMPILER_VERSION);
9000 #endif
9001     MrBayesPrint ("   ---------------------------------------------------------------------------\n");
9002 
9003     return (NO_ERROR);
9004 }
9005 
9006 
Expecting(int y)9007 BitsLong Expecting (int y)
9008 {
9009     BitsLong x;
9010 
9011     x = (BitsLong) pow (2.0, (MrBFlt)y);
9012 
9013     return (x);
9014 }
9015 
9016 
9017 #ifdef HAVE_LIBREADLINE
9018 /* This function is for commandline substitution: first word is always a command */
command_generator(const char * text,int state)9019 char *command_generator (const char *text, int state)
9020 {
9021     static int      list_index, len;
9022     char           *command;
9023     char           *dupstring;
9024 
9025     if (state == 0)
9026         {
9027         list_index = 0;
9028         len = (int) strlen (text);
9029         }
9030 
9031     while ((command = commands[list_index].string) != NULL)
9032         {
9033         list_index++;
9034 
9035         if (StrCmpCaseInsensitiveLen (command, text, len) == 0)
9036             {
9037             /* memory is freed by the readline library so we need a strdup here */
9038             dupstring = SafeMalloc (strlen (command) + 1);
9039             strcpy (dupstring, command);
9040             return dupstring;
9041             }
9042         }
9043 
9044     return NULL;
9045 }
9046 #endif
9047 
9048 
FindValidCommand(char * tk,int * numMatches)9049 int FindValidCommand (char *tk, int *numMatches)
9050 {
9051     int             i, j, tkLen, targetLen, numDiff;
9052     CmdType         *p;
9053 
9054     p = commands + 0;
9055     tkLen = (int) strlen(tk);
9056 
9057     (*numMatches) = 0;
9058     for (i=0; i<NUMCOMMANDS; i++)
9059         {
9060         targetLen = (int) strlen(p->string);
9061         if (tkLen <= targetLen)
9062             {
9063             for (j=0, numDiff=0; j<tkLen; j++)
9064                 {
9065                 if (ChangeCase(tk[j]) != ChangeCase(p->string[j]))
9066                     numDiff++;
9067                 }
9068             if (numDiff == 0)
9069                 {
9070                 (*numMatches)++;
9071                 commandPtr = p;
9072                 if (tkLen == targetLen)
9073                     break;
9074                 }
9075             }
9076         p++;
9077         }
9078 
9079     inValidCommand = NO;
9080     if (*numMatches == 1)
9081         {
9082         inValidCommand = YES;
9083         return (NO_ERROR);
9084         }
9085     else
9086         return (ERROR);
9087 }
9088 
9089 
FindValidParam(char * tk,int * numMatches)9090 int FindValidParam (char *tk, int *numMatches)
9091 {
9092     int         i, j, tkLen, targetLen, numDiff;
9093     CmdType     *p;
9094     ParmInfoPtr q;
9095 
9096     if (commandPtr)
9097         p = commandPtr;
9098     else
9099         {
9100         MrBayesPrint ("%s   Command pointer is NULL\n", spacer);
9101         return (ERROR);
9102         }
9103     tkLen = (int) strlen(tk);
9104 
9105     *numMatches = 0;
9106     for (i=0; i<p->numParms; i++)
9107         {
9108         q = paramTable + (p->parmList[i]);
9109         targetLen = (int) strlen(q->string);
9110         /* printf ("%s %d (%s %d)\n", q->string, targetLen, tk, p->numParms); */
9111         if (!strcmp(q->string, "Xxxxxxxxxx"))
9112             {
9113             (*numMatches)++;
9114             paramPtr = q;
9115             }
9116         else if (tkLen <= targetLen)
9117             {
9118             for (j=0, numDiff=0; j<tkLen; j++)
9119                 {
9120                 if (ChangeCase(tk[j]) != ChangeCase(q->string[j]))
9121                     numDiff++;
9122                 }
9123             if (numDiff == 0)
9124                 {
9125                 (*numMatches)++;
9126                 paramPtr = q;
9127                 if (tkLen == targetLen)
9128                     break;
9129                 }
9130             }
9131         }
9132 
9133     if (*numMatches == 1)
9134         return (NO_ERROR);
9135     else
9136         return (ERROR);
9137 }
9138 
9139 
FreeCharacters(void)9140 int FreeCharacters (void)
9141 {
9142     int     i, memoryLetFree;
9143 
9144     memoryLetFree = NO;
9145 
9146     if (memAllocs[ALLOC_TMPSET] == YES)
9147         {
9148         if (numChar > numTaxa)
9149             {
9150             tempSet = (int *) SafeRealloc ((void *)tempSet, (size_t)numTaxa*sizeof(int));
9151             tempSetNeg = (int *) SafeRealloc ((void *)tempSetNeg, (size_t)numTaxa*sizeof(int));
9152             }
9153         }
9154     if (memAllocs[ALLOC_MATRIX] == YES)
9155         {
9156         free (matrix);
9157         matrix = NULL;
9158         defMatrix = NO;
9159         memAllocs[ALLOC_MATRIX] = NO;
9160         memoryLetFree = YES;
9161         }
9162     if (memAllocs[ALLOC_CHARINFO] == YES)
9163         {
9164         free (charInfo);
9165         charInfo = NULL;
9166         memAllocs[ALLOC_CHARINFO] = NO;
9167         memoryLetFree = YES;
9168         }
9169     if (memAllocs[ALLOC_CHARSETS] == YES)
9170         {
9171         for (i=0; i<numCharSets; i++)
9172             {
9173             free (charSetNames[i]);
9174             free (charSet[i]);
9175             }
9176         free (charSetNames);
9177         free (charSet);
9178         charSetNames = NULL;
9179         charSet = NULL;
9180         numCharSets = 0;
9181         memAllocs[ALLOC_CHARSETS] = NO;
9182         memoryLetFree = YES;
9183         }
9184     if (memAllocs[ALLOC_PARTITIONS] == YES)
9185         {
9186         for (i=0; i<numDefinedPartitions; i++)
9187             free (partitionNames[i]);
9188         free (partitionNames);
9189         partitionNames = NULL;
9190         for (i=0; i<numChar; i++)
9191             free (partitionId[i]);
9192         free (partitionId);
9193         numDefinedPartitions = 0;
9194         memAllocs[ALLOC_PARTITIONS] = NO;
9195         memoryLetFree = YES;
9196         }
9197     if (memAllocs[ALLOC_PARTITIONVARS] == YES)
9198         {
9199         free (numVars);
9200         numVars = NULL;
9201         free (tempNum);
9202         tempNum = NULL;
9203         free (activeParams[0]);
9204         activeParams[0] = NULL;
9205         free (linkTable[0]);
9206         linkTable[0] = NULL;
9207         tempLinkUnlinkVec = NULL;
9208         activeParts = NULL;
9209         tempLinkUnlinkVec = NULL;
9210         for (i=0; i<NUM_LINKED; i++)
9211             {
9212             linkTable[i] = NULL;
9213             activeParams[i] = NULL;
9214             }
9215         memAllocs[ALLOC_PARTITIONVARS] = NO;
9216         memoryLetFree = YES;
9217         }
9218 
9219     ResetCharacterFlags();
9220 
9221     if (memoryLetFree == YES)
9222         MrBayesPrint ("%s   Deleting previously defined characters\n", spacer);
9223 
9224     return (NO_ERROR);
9225 }
9226 
9227 
FreeMatrix(void)9228 int FreeMatrix (void)
9229 {
9230     if (FreeCharacters() == ERROR)
9231         return ERROR;
9232 
9233     return (FreeTaxa());
9234 }
9235 
9236 
FreeTaxa(void)9237 int FreeTaxa (void)
9238 {
9239     int             i, memoryLetFree;
9240 
9241     memoryLetFree = NO;
9242 
9243     if (memAllocs[ALLOC_SPECIESPARTITIONS] == YES)
9244         {
9245         for (i = 0; i < numDefinedSpeciespartitions; i++)
9246             SAFEFREE (speciespartitionNames[i]);
9247 
9248         SAFEFREE (speciespartitionNames);
9249 
9250         for (i = 0; i < numTaxa; i++)
9251             SAFEFREE (speciespartitionId[i]);
9252 
9253         SAFEFREE (speciespartitionId);
9254         numDefinedSpeciespartitions = 0;
9255         memAllocs[ALLOC_SPECIESPARTITIONS] = NO;
9256         memoryLetFree = YES;
9257         }
9258 
9259     if (memAllocs[ALLOC_TAXA] == YES)
9260         {
9261         if (taxaNames)
9262             {
9263             for (i = 0; i < taxonCount; i++)
9264                 SAFEFREE (taxaNames[i]);
9265             }
9266 
9267         SAFEFREE (taxaNames);
9268         SAFEFREE (taxaInfo);
9269         SAFEFREE (tipCalibration);
9270         numTaxa = 0;
9271         memAllocs[ALLOC_TAXA] = NO;
9272         memoryLetFree = YES;
9273         }
9274 
9275     if (memAllocs[ALLOC_TMPSET] == YES)
9276         {
9277         SAFEFREE (tempSet);
9278         SAFEFREE (tempSetNeg);
9279         memAllocs[ALLOC_TMPSET] = NO;
9280         memoryLetFree = YES;
9281         }
9282 
9283     if (memAllocs[ALLOC_TAXASETS] == YES)
9284         {
9285         for (i = 0; i < numTaxaSets; i++)
9286             {
9287             SAFEFREE (taxaSetNames[i]);
9288             SAFEFREE (taxaSet[i]);
9289             }
9290 
9291         SAFEFREE (taxaSetNames);
9292         SAFEFREE (taxaSet);
9293         numTaxaSets = 0;
9294         memAllocs[ALLOC_TAXASETS] = NO;
9295         memoryLetFree = YES;
9296         }
9297 
9298     if (memAllocs[ALLOC_CONSTRAINTS] == YES)
9299         {
9300         for (i = 0; i < numDefinedConstraints; i++)
9301             {
9302             SAFEFREE (definedConstraint[i]);
9303             SAFEFREE (definedConstraintTwo[i]);
9304             SAFEFREE (definedConstraintPruned[i]);
9305             SAFEFREE (definedConstraintTwoPruned[i]);
9306             SAFEFREE (constraintNames[i]);
9307             }
9308 
9309         SAFEFREE (definedConstraint);
9310         SAFEFREE (definedConstraintTwo);
9311         SAFEFREE (definedConstraintsType);
9312         SAFEFREE (constraintNames);
9313         SAFEFREE (nodeCalibration);
9314         numDefinedConstraints = 0;
9315         SAFEFREE (tempActiveConstraints);
9316         memAllocs[ALLOC_CONSTRAINTS] = NO;
9317         memoryLetFree = YES;
9318         }
9319 
9320     if (numUserTrees > 0)
9321         {
9322         MrBayesPrint ("%s   Deleting user trees\n", spacer);
9323 
9324         for (i = 0; i < numUserTrees; i++)
9325             {
9326             FreePolyTree (userTree[i]);
9327             userTree[i] = NULL;
9328             }
9329 
9330         numUserTrees = 0;
9331         }
9332 
9333     FreeCharacters();
9334 
9335     if (memoryLetFree == YES)
9336         MrBayesPrint ("%s   Deleting previously defined taxa\n", spacer);
9337 
9338     /* reinitialize taxa variables */
9339     ResetTaxaFlags();
9340 
9341     return NO_ERROR;
9342 }
9343 
9344 
GetNumPartDivisions(int n)9345 int GetNumPartDivisions (int n)
9346 {
9347     int         i, maxDiv, numDivs, *divFound;
9348 
9349     maxDiv = 0;
9350     for (i=0; i<numChar; i++)
9351         if (partitionId[i][n] > maxDiv)
9352             maxDiv = partitionId[i][n];
9353 
9354     divFound = (int *) SafeCalloc (maxDiv, sizeof(int));
9355 
9356     for (i=0; i<maxDiv; i++)
9357         divFound[i] = NO;
9358 
9359     for (i=0; i<numChar; i++)
9360         divFound[partitionId[i][n]] = YES;
9361 
9362     numDivs = 0;
9363     for (i=0; i<maxDiv; i++)
9364         if (divFound[i] == YES)
9365             numDivs++;
9366 
9367     free (divFound);
9368 
9369     return (numDivs + 1);
9370 }
9371 
9372 
GetToken(char * token,int * tokenType,char ** sourceH)9373 int GetToken (char *token, int *tokenType, char **sourceH)
9374 {
9375     int             allNumbers, foundExp, foundExpSign;
9376     register char   *temp;
9377     char            *tempMax;
9378 
9379     (*tokenType) = 0;
9380     temp = token;
9381     tempMax = temp + CMD_STRING_LENGTH - 10;
9382 
9383     while (IsWhite(**sourceH) == 1 || IsWhite(**sourceH) == 2)
9384         {
9385         if (IsWhite(**sourceH) == 2)
9386             {
9387             *tokenType = RETURNSYMBOL;
9388             /* foundNewLine = YES;  Why is this commented out?? */
9389             /* MrBayesPrint ("RETURN\n"); */
9390             }
9391         ++(*sourceH);
9392         }
9393 
9394     if (readWord == YES && **sourceH != '"')
9395         {
9396         if (**sourceH==';')
9397             {
9398             *temp++ = ';';
9399             *tokenType = SEMICOLON;
9400             }
9401         else
9402             {
9403             while (isgraph(**sourceH) && **sourceH!=';')
9404                 {
9405                 if (temp > tempMax)
9406                     {
9407                     *tokenType = NOTHING;
9408                     token[20]='\0';
9409                     MrBayesPrint ("%s   Error while parsing a string. Token \"%s...[followed by at least %d  more charectors]\" is too long.\n", spacer,token,tempMax-token-20);
9410                     MrBayesPrint ("%s   Maximum allowed length of a token is %d\n", spacer,tempMax-token);
9411                     return (ERROR);
9412                     }
9413                 *temp++ = *(*sourceH)++;
9414                 }
9415             *tokenType = ALPHA;
9416             }
9417         *temp = '\0';
9418         readWord = NO;
9419         return (NO_ERROR);;
9420         }
9421 
9422     *tokenType = UNKNOWN_TOKEN_TYPE;
9423     if (IsIn(**sourceH,"="))
9424         {
9425         *temp++ = *(*sourceH)++;
9426         *tokenType = EQUALSIGN;
9427         }
9428     else if (IsIn(**sourceH,";"))
9429         {
9430         *temp++ = *(*sourceH)++;
9431         *tokenType = SEMICOLON;
9432         }
9433     else if (IsIn(**sourceH,":"))
9434         {
9435         *temp++ = *(*sourceH)++;
9436         *tokenType = COLON;
9437         }
9438     else if (IsIn(**sourceH,","))
9439         {
9440         *temp++ = *(*sourceH)++;
9441         *tokenType = COMMA;
9442         }
9443     else if (IsIn(**sourceH,"#"))
9444         {
9445         *temp++ = *(*sourceH)++;
9446         *tokenType = POUNDSIGN;
9447         }
9448     else if (IsIn(**sourceH,"("))
9449         {
9450         *temp++ = *(*sourceH)++;
9451         *tokenType = LEFTPAR;
9452         }
9453     else if (IsIn(**sourceH,")"))
9454         {
9455         *temp++ = *(*sourceH)++;
9456         *tokenType = RIGHTPAR;
9457         }
9458     else if (IsIn(**sourceH,"{"))
9459         {
9460         *temp++ = *(*sourceH)++;
9461         *tokenType = LEFTCURL;
9462         }
9463     else if (IsIn(**sourceH,"}"))
9464         {
9465         *temp++ = *(*sourceH)++;
9466         *tokenType = RIGHTCURL;
9467         }
9468     else if (IsIn(**sourceH,"["))
9469         {
9470         *temp++ = *(*sourceH)++;
9471         *tokenType = LEFTCOMMENT;
9472         }
9473     else if (IsIn(**sourceH,"]"))
9474         {
9475         *temp++ = *(*sourceH)++;
9476         *tokenType = RIGHTCOMMENT;
9477         }
9478     else if (IsIn(**sourceH,"?"))
9479         {
9480         *temp++ = *(*sourceH)++;
9481         *tokenType = QUESTIONMARK;
9482         }
9483     else if (IsIn(**sourceH,"-"))
9484         {
9485         *temp++ = *(*sourceH)++;
9486         *tokenType = DASH;
9487         }
9488     else if (IsIn(**sourceH,"$"))
9489         {
9490         *temp++ = *(*sourceH)++;
9491         *tokenType = DOLLAR;
9492         }
9493     else if (IsIn(**sourceH,"\"") && readWord == YES)
9494         {
9495         (*sourceH)++;
9496         while (**sourceH != '"' && **sourceH != '\0')
9497             {
9498             if (temp > tempMax)
9499                 {
9500                 *tokenType = NOTHING;
9501                 token[20]='\0';
9502                 MrBayesPrint ("%s   Error while parsing a string. Token \"%s...[followed by at least %d  more charectors]\" is too long.\n", spacer,token,tempMax-token-20);
9503                 MrBayesPrint ("%s   Maximum allowed length of a token is %d\n", spacer,tempMax-token);
9504                 return (ERROR);
9505                 }
9506             *temp++ = *((*sourceH)++);
9507             }
9508         *temp='\0';
9509         *tokenType = ALPHA;
9510         (*sourceH)++;
9511         readWord = NO;
9512         }
9513     else if (IsIn(**sourceH,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789."))
9514         {
9515         if (IsIn(**sourceH,"0123456789."))
9516             allNumbers = TRUE;
9517         else
9518             allNumbers = FALSE;
9519         foundExp = foundExpSign = FALSE;
9520         *temp++ = *(*sourceH)++;
9521         while (IsIn(**sourceH,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789.-+"))
9522             {
9523             if (temp > tempMax)
9524                 {
9525                 *tokenType = NOTHING;
9526                 token[20]='\0';
9527                 MrBayesPrint ("%s   Error while parsing a string. Token \"%s...[followed by at least %d  more charectors]\" is too long.\n", spacer,token,tempMax-token-20);
9528                 MrBayesPrint ("%s   Maximum allowed length of a token is %d\n", spacer,tempMax-token);
9529                 return (ERROR);
9530                 }
9531             if (allNumbers == TRUE && !IsIn((*sourceH)[-1],"Ee") && **sourceH=='-')
9532                 break;
9533             else if (allNumbers == TRUE && IsIn(**sourceH,"Ee") && foundExp == NO)
9534                 foundExp = TRUE;
9535             else if (allNumbers == TRUE && IsIn(**sourceH,"+-") && IsIn((*sourceH)[-1],"Ee"))
9536                 foundExpSign = TRUE; /* FIXME: Not used (from clang static analyzer) */
9537             else if (!IsIn(**sourceH,"0123456789."))
9538                 allNumbers = FALSE;
9539             *temp++ = *(*sourceH)++;
9540             }
9541         if (allNumbers == TRUE)
9542             *tokenType = NUMBER;
9543         else
9544             *tokenType = ALPHA;
9545         }
9546     else if (IsIn(**sourceH,"*"))
9547         {
9548         *temp++ = *(*sourceH)++;
9549         *tokenType = ASTERISK;
9550         }
9551     else if (IsIn(**sourceH,"/"))
9552         {
9553         *temp++ = *(*sourceH)++;
9554         *tokenType = FORWARDSLASH;
9555         }
9556     else if (IsIn(**sourceH,"'\\'"))
9557         {
9558         *temp++ = *(*sourceH)++;
9559         *tokenType = BACKSLASH;
9560         }
9561     else if (IsIn(**sourceH,"!"))
9562         {
9563         *temp++ = *(*sourceH)++;
9564         *tokenType = EXCLAMATIONMARK;
9565         }
9566     else if (IsIn(**sourceH,"%"))
9567         {
9568         *temp++ = *(*sourceH)++;
9569         *tokenType = PERCENT;
9570         }
9571     else if (IsIn(**sourceH,"\""))
9572         {
9573         *temp++ = *(*sourceH)++;
9574         *tokenType = QUOTATIONMARK;
9575         }
9576     else if (IsIn(**sourceH,"&"))
9577         {
9578         *temp++ = *(*sourceH)++;
9579         *tokenType = AMPERSAND;
9580         }
9581     else if (IsIn(**sourceH,"~+^@{}`><"))
9582         {
9583         *temp++ = *(*sourceH)++;
9584         *tokenType = WEIRD;
9585         }
9586     else if (IsIn(**sourceH,"|"))
9587         {
9588         *temp++ = *(*sourceH)++;
9589         *tokenType = VERTICALBAR;
9590         }
9591 
9592     *temp = '\0';
9593     return (NO_ERROR);
9594 }
9595 
9596 
GetUserHelp(char * helpTkn)9597 int GetUserHelp (char *helpTkn)
9598 {
9599     int         i, j, k, tempInt;
9600     char        tempString[100];
9601     Model       *mp;
9602 
9603     if (!strcmp(helpTkn, "Begin"))
9604         {
9605         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9606         MrBayesPrint ("   Begin                                                                         \n");
9607         MrBayesPrint ("                                                                                 \n");
9608         MrBayesPrint ("   This command is used to format data or commands in the program. The correct   \n");
9609         MrBayesPrint ("   usage is                                                                      \n");
9610         MrBayesPrint ("                                                                                 \n");
9611         MrBayesPrint ("      begin <data or mrbayes>;                                                   \n");
9612         MrBayesPrint ("                                                                                 \n");
9613         MrBayesPrint ("   The two valid uses of the \"begin\" command, then, are                        \n");
9614         MrBayesPrint ("                                                                                 \n");
9615         MrBayesPrint ("      begin data;                                                                \n");
9616         MrBayesPrint ("      begin mrbayes;                                                             \n");
9617         MrBayesPrint ("                                                                                 \n");
9618         MrBayesPrint ("   The \"data\" specifier is used to specify the beginning of a data block; your \n");
9619         MrBayesPrint ("   character data should follow. For example, the following is an example of     \n");
9620         MrBayesPrint ("   a data block for four taxa and ten DNA sites:                                 \n");
9621         MrBayesPrint ("                                                                                 \n");
9622         MrBayesPrint ("      begin data;                                                                \n");
9623         MrBayesPrint ("         dimensions ntax=4 nchar=10;                                             \n");
9624         MrBayesPrint ("         format datatype=dna;                                                    \n");
9625         MrBayesPrint ("         matrix                                                                  \n");
9626         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9627         MrBayesPrint ("         taxon_2  AAGGATTCCA                                                     \n");
9628         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9629         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9630         MrBayesPrint ("         ;                                                                       \n");
9631         MrBayesPrint ("      end;                                                                       \n");
9632         MrBayesPrint ("                                                                                 \n");
9633         MrBayesPrint ("   The other commands -- dimensions, format, and matrix -- are discussed         \n");
9634         MrBayesPrint ("   in the appropriate help menu. The only thing to note here is that the         \n");
9635         MrBayesPrint ("   block begins with a \"begin data\" command. The \"mrbayes\" command is        \n");
9636         MrBayesPrint ("   used to enter commands specific to the MrBayes program into the file.         \n");
9637         MrBayesPrint ("   This allows you to automatically process commands on execution of the         \n");
9638         MrBayesPrint ("   program. The following is a simple mrbayes block:                             \n");
9639         MrBayesPrint ("                                                                                 \n");
9640         MrBayesPrint ("      begin mrbayes;                                                             \n");
9641         MrBayesPrint ("         charset first  = 1-10\\3;                                               \n");
9642         MrBayesPrint ("         charset second = 2-10\\3;                                               \n");
9643         MrBayesPrint ("         charset third  = 3-10\\3;                                               \n");
9644         MrBayesPrint ("      end;                                                                       \n");
9645         MrBayesPrint ("                                                                                 \n");
9646         MrBayesPrint ("   This mrbayes block sets off the three \"charset\" commands, used to           \n");
9647         MrBayesPrint ("   predefine some blocks of characters. The mrbayes block can be very useful.    \n");
9648         MrBayesPrint ("   For example, in this case, it would save you the time of typing the char-     \n");
9649         MrBayesPrint ("   acter sets each time you executed the file. Also, note that every             \n");
9650         MrBayesPrint ("   \"begin <data or mrbayes>\" command ends with an \"end\". Finally, you can    \n");
9651         MrBayesPrint ("   have so-called foreign blocks in the file. An example of a foreign block      \n");
9652         MrBayesPrint ("   would be \"begin paup\". The program will simply skip this block. This is     \n");
9653         MrBayesPrint ("   useful because it means that you can use the same file for MrBayes, PAUP*     \n");
9654         MrBayesPrint ("   or MacClade (although it isn't clear why you would want to use those other    \n");
9655         MrBayesPrint ("   programs).                                                                    \n");
9656         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9657         }
9658     else if (!strcmp(helpTkn, "End"))
9659         {
9660         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9661         MrBayesPrint ("   End                                                                           \n");
9662         MrBayesPrint ("                                                                                 \n");
9663         MrBayesPrint ("   This command is used to terminate a data or mrbayes block. The correct        \n");
9664         MrBayesPrint ("   usage is                                                                      \n");
9665         MrBayesPrint ("                                                                                 \n");
9666         MrBayesPrint ("      end;                                                                       \n");
9667         MrBayesPrint ("                                                                                 \n");
9668         MrBayesPrint ("   For more information on this, check the help for the \"begin\" command.       \n");
9669         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9670         }
9671     else if (!strcmp(helpTkn, "Endblock"))
9672         {
9673         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9674         MrBayesPrint ("   Endblock                                                                      \n");
9675         MrBayesPrint ("                                                                                 \n");
9676         MrBayesPrint ("   This is an older, deprecated version of \"End\", see that command.            \n");
9677         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9678         }
9679     else if (!strcmp(helpTkn, "Plot"))
9680         {
9681         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9682         MrBayesPrint ("   Plot                                                                          \n");
9683         MrBayesPrint ("                                                                                 \n");
9684         MrBayesPrint ("   This command plots specified parameters in the .p file or one of the .p files \n");
9685         MrBayesPrint ("   created during an MCMC analysis. An x-y graph of the parameter over the course\n");
9686         MrBayesPrint ("   of the chain is created. The command can be useful for visually diagnosing    \n");
9687         MrBayesPrint ("   convergence for many of the parameters of the phylogenetic model. The para-   \n");
9688         MrBayesPrint ("   meter to be plotted is specified by the \"parameter\" option. Several para-   \n");
9689         MrBayesPrint ("   meters can be plotted at once by using the \"match\" option, which has a      \n");
9690         MrBayesPrint ("   default value of \"perfect\". For example, if you were to set \"parameter = pi\"\n");
9691         MrBayesPrint ("   and \"match = consistentwith\", then all of the state frequency parameters    \n");
9692         MrBayesPrint ("   would be plotted. You can also set \"match=all\", in which case all of the    \n");
9693         MrBayesPrint ("   parameters are plotted.                                                       \n");
9694         MrBayesPrint ("                                                                                 \n");
9695         MrBayesPrint ("   Note that the \"Sump\" command provides a different set of convergence diag-  \n");
9696         MrBayesPrint ("   nostics tools that you may also want to explore. Unlike \"Plot\", \"Sump\" can\n");
9697         MrBayesPrint ("   compare two or more parameter samples and will calculate convergence diagnos- \n");
9698         MrBayesPrint ("   tics as wel as parameter summaries for the pooled sample.                     \n");
9699         MrBayesPrint ("                                                                                 \n");
9700         MrBayesPrint ("   Options:                                                                      \n");
9701         MrBayesPrint ("                                                                                 \n");
9702         MrBayesPrint ("   Relburnin     -- If this option is set to 'Yes', then a proportion of the     \n");
9703         MrBayesPrint ("                    samples will be discarded as burnin when creating the plot.  \n");
9704         MrBayesPrint ("                    The proportion to be discarded is set with Burninfrac (see   \n");
9705         MrBayesPrint ("                    Burninfrac below). When the Relburnin option is set to 'No', \n");
9706         MrBayesPrint ("                    then a specific number of samples is discarded instead. This \n");
9707         MrBayesPrint ("                    number is set by Burnin (see below). Note that the burnin    \n");
9708         MrBayesPrint ("                    setting is shared across the 'comparetree', 'sump' and 'sumt'\n");
9709         MrBayesPrint ("                    commands.                                                    \n");
9710         MrBayesPrint ("   Burnin        -- Determines the number of samples (not generations) that will \n");
9711         MrBayesPrint ("                    be discarded when summary statistics are calculated. The     \n");
9712         MrBayesPrint ("                    value of this option is only relevant when Relburnin is set  \n");
9713         MrBayesPrint ("                    to 'No'.                                                     \n");
9714         MrBayesPrint ("   Burninfrac    -- Determines the fraction of samples that will be discarded    \n");
9715         MrBayesPrint ("                    when creating a plot. The value of this parameter is only    \n");
9716         MrBayesPrint ("                    relevant when Relburnin is set to 'Yes'. Example: A value of \n");
9717         MrBayesPrint ("                    this option of 0.25 means that 25%% of the samples will be   \n");
9718         MrBayesPrint ("                    discarded.                                                   \n");
9719         MrBayesPrint ("   Filename      -- The name of the file to plot.                                \n");
9720         MrBayesPrint ("   Parameter     -- Specification of parameters to be plotted. See above for     \n");
9721         MrBayesPrint ("                    details.                                                     \n");
9722         MrBayesPrint ("   Match         -- Specifies how to match parameter names to the Parameter      \n");
9723         MrBayesPrint ("                    specification. See above for details.                        \n");
9724         MrBayesPrint ("                                                                                 \n");
9725         MrBayesPrint ("   Current settings:                                                             \n");
9726         MrBayesPrint ("                                                                                 \n");
9727         MrBayesPrint ("   Parameter       Options                      Current Setting                  \n");
9728         MrBayesPrint ("   ------------------------------------------------------------                  \n");
9729         MrBayesPrint ("   Relburnin       Yes/No                       %s                               \n", chainParams.relativeBurnin == YES ? "Yes" : "No");
9730         MrBayesPrint ("   Burnin          <number>                     %d                               \n", chainParams.chainBurnIn);
9731         MrBayesPrint ("   Burninfrac      <number>                     %1.2lf                           \n", chainParams.burninFraction);
9732         MrBayesPrint ("   Filename        <name>                       %s                               \n", plotParams.plotFileName);
9733         MrBayesPrint ("   Parameter       <name>                       %s                               \n", plotParams.parameter);
9734         MrBayesPrint ("   Match           Perfect/Consistentwith/All   %s                               \n", plotParams.match);
9735         MrBayesPrint ("                                                                                 \n");
9736         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9737         }
9738     else if (!strcmp(helpTkn, "Dimensions"))
9739         {
9740         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9741         MrBayesPrint ("   Dimensions                                                                    \n");
9742         MrBayesPrint ("                                                                                 \n");
9743         MrBayesPrint ("   This command is used in a data block to define the number of taxa and         \n");
9744         MrBayesPrint ("   characters. The correct usage is                                              \n");
9745         MrBayesPrint ("                                                                                 \n");
9746         MrBayesPrint ("      dimensions ntax=<number> nchar=<number>                                    \n");
9747         MrBayesPrint ("                                                                                 \n");
9748         MrBayesPrint ("   The dimensions must be the first command in a data block. The following       \n");
9749         MrBayesPrint ("   provides an example of the proper use of this command:                        \n");
9750         MrBayesPrint ("                                                                                 \n");
9751         MrBayesPrint ("      begin data;                                                                \n");
9752         MrBayesPrint ("         dimensions ntax=4 nchar=10;                                             \n");
9753         MrBayesPrint ("         format datatype=dna;                                                    \n");
9754         MrBayesPrint ("         matrix                                                                  \n");
9755         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9756         MrBayesPrint ("         taxon_2  AAGGATTCCA                                                     \n");
9757         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9758         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9759         MrBayesPrint ("         ;                                                                       \n");
9760         MrBayesPrint ("      end;                                                                       \n");
9761         MrBayesPrint ("                                                                                 \n");
9762         MrBayesPrint ("   Here, the dimensions command tells MrBayes to expect a matrix with four       \n");
9763         MrBayesPrint ("   taxa and 10 characters.                                                       \n");
9764         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9765         }
9766     else if (!strcmp(helpTkn, "Format"))
9767         {
9768         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9769         MrBayesPrint ("   Format                                                                        \n");
9770         MrBayesPrint ("                                                                                 \n");
9771         MrBayesPrint ("   This command is used in a data block to define the format of the char-        \n");
9772         MrBayesPrint ("   acter matrix. The correct usage is                                            \n");
9773         MrBayesPrint ("                                                                                 \n");
9774         MrBayesPrint ("      format datatype=<name> ... <parameter>=<option>                            \n");
9775         MrBayesPrint ("                                                                                 \n");
9776         MrBayesPrint ("   The format command must be the second command in a data block. The following  \n");
9777         MrBayesPrint ("   provides an example of the proper use of this command:                        \n");
9778         MrBayesPrint ("                                                                                 \n");
9779         MrBayesPrint ("      begin data;                                                                \n");
9780         MrBayesPrint ("         dimensions ntax=4 nchar=10;                                             \n");
9781         MrBayesPrint ("         format datatype=dna gap=-;                                              \n");
9782         MrBayesPrint ("         matrix                                                                  \n");
9783         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9784         MrBayesPrint ("         taxon_2  AAGGAT--CA                                                     \n");
9785         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9786         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9787         MrBayesPrint ("         ;                                                                       \n");
9788         MrBayesPrint ("      end;                                                                       \n");
9789         MrBayesPrint ("                                                                                 \n");
9790         MrBayesPrint ("   Here, the format command tells MrBayes to expect a matrix with DNA char-      \n");
9791         MrBayesPrint ("   acters and with gaps coded as \"-\".                                          \n");
9792         MrBayesPrint ("                                                                                 \n");
9793         MrBayesPrint ("   The following are valid options for format:                                   \n");
9794         MrBayesPrint ("                                                                                 \n");
9795         MrBayesPrint ("   Datatype   -- This parameter MUST BE INCLUDED in the format command. More-    \n");
9796         MrBayesPrint ("                 over, it must be the first parameter in the line. The           \n");
9797         MrBayesPrint ("                 datatype command specifies what type of characters are          \n");
9798         MrBayesPrint ("                 in the matrix. The following are valid options:                 \n");
9799         MrBayesPrint ("                    Datatype = Dna: DNA states (A,C,G,T,R,Y,M,K,S,W,H,B,         \n");
9800         MrBayesPrint ("                               V,D,N)                                            \n");
9801         MrBayesPrint ("                    Datatype = Rna: DNA states (A,C,G,U,R,Y,M,K,S,W,H,B,         \n");
9802         MrBayesPrint ("                               V,D,N)                                            \n");
9803         MrBayesPrint ("                    Datatype = Protein: Amino acid states (A,R,N,D,C,Q,E,        \n");
9804         MrBayesPrint ("                               G,H,I,L,K,M,F,P,S,T,W,Y,V)                        \n");
9805         MrBayesPrint ("                    Datatype = Restriction: Restriction site (0,1) states        \n");
9806         MrBayesPrint ("                    Datatype = Standard: Morphological (0,1) states              \n");
9807         MrBayesPrint ("                    Datatype = Continuous: Real number valued states             \n");
9808         MrBayesPrint ("                    Datatype = Mixed(<type>:<range>,...,<type>:<range>): A       \n");
9809         MrBayesPrint ("                               mixture of the above datatypes. For example,      \n");
9810         MrBayesPrint ("                               \"datatype=mixed(dna:1-100,protein:101-200)\"     \n");
9811         MrBayesPrint ("                               would specify a mixture of DNA and amino acid     \n");
9812         MrBayesPrint ("                               characters with the DNA characters occupying      \n");
9813         MrBayesPrint ("                               the first 100 sites and the amino acid char-      \n");
9814         MrBayesPrint ("                               acters occupying the last 100 sites.              \n");
9815         MrBayesPrint ("                                                                                 \n");
9816         MrBayesPrint ("   Interleave -- This parameter specifies whether the data matrix is in          \n");
9817         MrBayesPrint ("                 interleave format. The valid options are \"Yes\" or \"No\",     \n");
9818         MrBayesPrint ("                 with \"No\" as the default. An interleaved matrix looks like    \n");
9819         MrBayesPrint ("                                                                                 \n");
9820         MrBayesPrint ("                    format datatype=dna gap=- interleave=yes;                    \n");
9821         MrBayesPrint ("                    matrix                                                       \n");
9822         MrBayesPrint ("                    taxon_1  AACGATTCGT                                          \n");
9823         MrBayesPrint ("                    taxon_2  AAGGAT--CA                                          \n");
9824         MrBayesPrint ("                    taxon_3  AACGACTCCT                                          \n");
9825         MrBayesPrint ("                    taxon_4  AAGGATTCCT                                          \n");
9826         MrBayesPrint ("                                                                                 \n");
9827         MrBayesPrint ("                    taxon_1  CCTGGTAC                                            \n");
9828         MrBayesPrint ("                    taxon_2  CCTGGTAC                                            \n");
9829         MrBayesPrint ("                    taxon_3  ---GGTAG                                            \n");
9830         MrBayesPrint ("                    taxon_4  ---GGTAG                                            \n");
9831         MrBayesPrint ("                    ;                                                            \n");
9832         MrBayesPrint ("                                                                                 \n");
9833         MrBayesPrint ("   Gap        -- This parameter specifies the format for gaps. Note that         \n");
9834         MrBayesPrint ("                 gap character can only be a single character and that it        \n");
9835         MrBayesPrint ("                 cannot correspond to a standard state (e.g., A,C,G,T,R,Y,       \n");
9836         MrBayesPrint ("                 M,K,S,W,H,B,V,D,N for nucleotide data).                         \n");
9837         MrBayesPrint ("                                                                                 \n");
9838         MrBayesPrint ("   Missing    -- This parameter specifies the format for missing data. Note      \n");
9839         MrBayesPrint ("                 that the missing character can only be a single character and   \n");
9840         MrBayesPrint ("                 cannot correspond to a standard state (e.g., A,C,G,T,R,Y,       \n");
9841         MrBayesPrint ("                 M,K,S,W,H,B,V,D,N for nucleotide data). This is often an        \n");
9842         MrBayesPrint ("                 unnecessary parameter to set because many data types, such      \n");
9843         MrBayesPrint ("                 as nucleotide or amino acid, already have a missing char-       \n");
9844         MrBayesPrint ("                 acter specified. However, for morphological or restriction      \n");
9845         MrBayesPrint ("                 site data, \"missing=?\" is often used to specify ambiguity     \n");
9846         MrBayesPrint ("                 or unobserved data.                                             \n");
9847         MrBayesPrint ("                                                                                 \n");
9848         MrBayesPrint ("   Matchchar  -- This parameter specifies the matching character for the         \n");
9849         MrBayesPrint ("                 matrix. For example,                                            \n");
9850         MrBayesPrint ("                                                                                 \n");
9851         MrBayesPrint ("                    format datatype=dna gap=- matchchar=.;                       \n");
9852         MrBayesPrint ("                    matrix                                                       \n");
9853         MrBayesPrint ("                    taxon_1  AACGATTCGT                                          \n");
9854         MrBayesPrint ("                    taxon_2  ..G...--CA                                          \n");
9855         MrBayesPrint ("                    taxon_3  .....C..C.                                          \n");
9856         MrBayesPrint ("                    taxon_4  ..G.....C.                                          \n");
9857         MrBayesPrint ("                    ;                                                            \n");
9858         MrBayesPrint ("                                                                                 \n");
9859         MrBayesPrint ("                 is equivalent to                                                \n");
9860         MrBayesPrint ("                                                                                 \n");
9861         MrBayesPrint ("                    format datatype=dna gap=-;                                   \n");
9862         MrBayesPrint ("                    matrix                                                       \n");
9863         MrBayesPrint ("                    taxon_1  AACGATTCGT                                          \n");
9864         MrBayesPrint ("                    taxon_2  AAGGAT--CA                                          \n");
9865         MrBayesPrint ("                    taxon_3  AACGACTCCT                                          \n");
9866         MrBayesPrint ("                    taxon_4  AAGGATTCCT                                          \n");
9867         MrBayesPrint ("                    ;                                                            \n");
9868         MrBayesPrint ("                                                                                 \n");
9869         MrBayesPrint ("   The only non-standard NEXUS format option is the use of the \"mixed\",        \n");
9870         MrBayesPrint ("   \"restriction\", \"standard\" and \"continuous\" datatypes. Hence, if         \n");
9871         MrBayesPrint ("   you use any of these datatype specifiers, a program like PAUP* or             \n");
9872         MrBayesPrint ("   MacClade will report an error (as they should because MrBayes is not          \n");
9873         MrBayesPrint ("   strictly NEXUS compliant).                                                    \n");
9874         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9875         }
9876     else if (!strcmp(helpTkn, "Matrix"))
9877         {
9878         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9879         MrBayesPrint ("   Matrix                                                                        \n");
9880         MrBayesPrint ("                                                                                 \n");
9881         MrBayesPrint ("   This command specifies the actual data for the phylogenetic analysis.         \n");
9882         MrBayesPrint ("   The character matrix should follow the dimensions and format commands         \n");
9883         MrBayesPrint ("   in a data block. The matrix can have all of the characters for a taxon        \n");
9884         MrBayesPrint ("   on a single line:                                                             \n");
9885         MrBayesPrint ("                                                                                 \n");
9886         MrBayesPrint ("      begin data;                                                                \n");
9887         MrBayesPrint ("         dimensions ntax=4 nchar=10;                                             \n");
9888         MrBayesPrint ("         format datatype=dna gap=-;                                              \n");
9889         MrBayesPrint ("         matrix                                                                  \n");
9890         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9891         MrBayesPrint ("         taxon_2  AAGGAT--CA                                                     \n");
9892         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9893         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9894         MrBayesPrint ("         ;                                                                       \n");
9895         MrBayesPrint ("      end;                                                                       \n");
9896         MrBayesPrint ("                                                                                 \n");
9897         MrBayesPrint ("   or be in \"interleaved\" format:                                              \n");
9898         MrBayesPrint ("                                                                                 \n");
9899         MrBayesPrint ("      begin data;                                                                \n");
9900         MrBayesPrint ("         dimensions ntax=4 nchar=20;                                             \n");
9901         MrBayesPrint ("         format datatype=dna gap=- interleave=yes;                               \n");
9902         MrBayesPrint ("         matrix                                                                  \n");
9903         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9904         MrBayesPrint ("         taxon_2  AAGGAT--CA                                                     \n");
9905         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9906         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9907         MrBayesPrint ("                                                                                 \n");
9908         MrBayesPrint ("         taxon_1  TTTTCGAAGC                                                     \n");
9909         MrBayesPrint ("         taxon_2  TTTTCGGAGC                                                     \n");
9910         MrBayesPrint ("         taxon_3  TTTTTGATGC                                                     \n");
9911         MrBayesPrint ("         taxon_4  TTTTCGGAGC                                                     \n");
9912         MrBayesPrint ("         ;                                                                       \n");
9913         MrBayesPrint ("      end;                                                                       \n");
9914         MrBayesPrint ("                                                                                 \n");
9915         MrBayesPrint ("   Note that the taxon names must not have spaces. If you really want to         \n");
9916         MrBayesPrint ("   indicate a space in a taxon name (perhaps between a genus and species         \n");
9917         MrBayesPrint ("   name), then you might use an underline (\"_\"). There should be at            \n");
9918         MrBayesPrint ("   least a single space after the taxon name, separating the name from           \n");
9919         MrBayesPrint ("   the actual data on that line. There can be spaces between the char-           \n");
9920         MrBayesPrint ("   acters.                                                                       \n");
9921         MrBayesPrint ("                                                                                 \n");
9922         MrBayesPrint ("   If you have mixed data, then you specify all of the data in the same          \n");
9923         MrBayesPrint ("   matrix. Here is an example that includes two different data types:            \n");
9924         MrBayesPrint ("                                                                                 \n");
9925         MrBayesPrint ("      begin data;                                                                \n");
9926         MrBayesPrint ("         dimensions ntax=4 nchar=20;                                             \n");
9927         MrBayesPrint ("         format datatype=mixed(dna:1-10,standard:21-30) interleave=yes;          \n");
9928         MrBayesPrint ("         matrix                                                                  \n");
9929         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9930         MrBayesPrint ("         taxon_2  AAGGAT--CA                                                     \n");
9931         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9932         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9933         MrBayesPrint ("                                                                                 \n");
9934         MrBayesPrint ("         taxon_1  0001111111                                                     \n");
9935         MrBayesPrint ("         taxon_2  0111110000                                                     \n");
9936         MrBayesPrint ("         taxon_3  1110000000                                                     \n");
9937         MrBayesPrint ("         taxon_4  1000001111                                                     \n");
9938         MrBayesPrint ("         ;                                                                       \n");
9939         MrBayesPrint ("      end;                                                                       \n");
9940         MrBayesPrint ("                                                                                 \n");
9941         MrBayesPrint ("   The matrix command is terminated by a semicolon.                              \n");
9942         MrBayesPrint ("                                                                                 \n");
9943         MrBayesPrint ("   Finally, just a note on data presentation. It is much easier for others       \n");
9944         MrBayesPrint ("   to (1) understand your data and (2) repeat your analyses if you make          \n");
9945         MrBayesPrint ("   your data clean, comment it liberally (using the square brackets), and        \n");
9946         MrBayesPrint ("   embed the commands you used in a publication in the mrbayes block.            \n");
9947         MrBayesPrint ("   Remember that the data took a long time for you to collect. You might         \n");
9948         MrBayesPrint ("   as well spend a little time making the data file look nice and clear to       \n");
9949         MrBayesPrint ("   any that may later request the data for further analysis.                     \n");
9950         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9951         }
9952     else if (!strcmp(helpTkn, "Pairs"))
9953         {
9954         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9955         MrBayesPrint ("   Pairs                                                                         \n");
9956         MrBayesPrint ("                                                                                 \n");
9957         MrBayesPrint ("   This command is used to specify pairs of nucleotides. For example, your       \n");
9958         MrBayesPrint ("   data may be RNA sequences with a known secondary structure of stems and       \n");
9959         MrBayesPrint ("   loops. Substitutions in nucleotides involved in a Watson-Crick pairing        \n");
9960         MrBayesPrint ("   in stems are not strictly independent; a change in one changes the prob-      \n");
9961         MrBayesPrint ("   ability of a change in the partner. A solution to this problem is to          \n");
9962         MrBayesPrint ("   expand the model around the pair of nucleotides in the stem. This             \n");
9963         MrBayesPrint ("   command allows you to do this. The correct usage is:                          \n");
9964         MrBayesPrint ("                                                                                 \n");
9965         MrBayesPrint ("      pairs <NUC1>:<NUC2>, <NUC1>:<NUC2>,..., <NUC1>:<NUC2>;                     \n");
9966         MrBayesPrint ("                                                                                 \n");
9967         MrBayesPrint ("   For example,                                                                  \n");
9968         MrBayesPrint ("                                                                                 \n");
9969         MrBayesPrint ("      pairs 30:56, 31:55, 32:54, 33:53, 34:52, 35:51, 36:50;                     \n");
9970         MrBayesPrint ("                                                                                 \n");
9971         MrBayesPrint ("   specifies pairings between nucleotides 30 and 56, 31 and 55, etc. Only        \n");
9972         MrBayesPrint ("   nucleotide data (DNA or RNA) may be paired using this command. Note that      \n");
9973         MrBayesPrint ("   in order for the program to actually implement a \"doublet\" model            \n");
9974         MrBayesPrint ("   involving a 16 X 16 rate matrix, you must specify that the structure of       \n");
9975         MrBayesPrint ("   the model is 16 X 16 using \"lset nucmodel=doublet\".                         \n");
9976         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9977         }
9978     else if (!strcmp(helpTkn, "Databreaks"))
9979         {
9980         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9981         MrBayesPrint ("   Databreaks                                                                    \n");
9982         MrBayesPrint ("                                                                                 \n");
9983         MrBayesPrint ("   This command is used to specify breaks in your input data matrix. Your        \n");
9984         MrBayesPrint ("   data may be a mixture of genes or a mixture of different types of data.       \n");
9985         MrBayesPrint ("   Some of the models implemented by MrBayes account for nonindependence at      \n");
9986         MrBayesPrint ("   adjacent characters. The autocorrelated gamma model, for example, allows      \n");
9987         MrBayesPrint ("   rates at adjacent sites to be correlated. However, there is no way for        \n");
9988         MrBayesPrint ("   such a model to tell whether two sites, adjacent in the matrix, are           \n");
9989         MrBayesPrint ("   actually separated by many kilobases or megabases in the genome. The          \n");
9990         MrBayesPrint ("   databreaks command allows you to specify such breaks. The correct             \n");
9991         MrBayesPrint ("   usage is:                                                                     \n");
9992         MrBayesPrint ("                                                                                 \n");
9993         MrBayesPrint ("      databreaks <break 1> <break 2> <break 3> ...                               \n");
9994         MrBayesPrint ("                                                                                 \n");
9995         MrBayesPrint ("   For example, say you have a data matrix of 3204 characters that include       \n");
9996         MrBayesPrint ("   nucleotide data from three genes. The first gene covers characters 1 to       \n");
9997         MrBayesPrint ("   970, the second gene covers characters 971 to 2567, and the third gene        \n");
9998         MrBayesPrint ("   covers characters 2568 to 3204. Also, let's assume that the genes are         \n");
9999         MrBayesPrint ("   not directly adjacent to one another in the genome, as might be likely        \n");
10000         MrBayesPrint ("   if you have mitochondrial sequences. In this case, you can specify            \n");
10001         MrBayesPrint ("   breaks between the genes using:                                               \n");
10002         MrBayesPrint ("                                                                                 \n");
10003         MrBayesPrint ("      databreaks 970 2567;                                                       \n");
10004         MrBayesPrint ("                                                                                 \n");
10005         MrBayesPrint ("   The first break, between genes one and two, is after character 970 and        \n");
10006         MrBayesPrint ("   the second break, between genes two and three, is after character 2567.       \n");
10007         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10008         }
10009     else if (!strcmp(helpTkn, "Acknowledgments"))
10010         {
10011         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10012         MrBayesPrint ("   Acknowledgments                                                               \n");
10013         MrBayesPrint ("                                                                                 \n");
10014         MrBayesPrint ("   This command shows the authors' acknowledgments.                              \n");
10015         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10016         }
10017     else if (!strcmp(helpTkn, "About"))
10018         {
10019         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10020         MrBayesPrint ("   About                                                                         \n");
10021         MrBayesPrint ("                                                                                 \n");
10022         MrBayesPrint ("   This command provides some general information about the program.             \n");
10023         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10024         }
10025     else if (!strcmp(helpTkn, "Version"))
10026         {
10027         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10028         MrBayesPrint ("   Version                                                                       \n");
10029         MrBayesPrint ("                                                                                 \n");
10030         MrBayesPrint ("   This command shows the release version of the program.                        \n");
10031         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10032         }
10033     else if (!strcmp(helpTkn, "Citations"))
10034         {
10035         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10036         MrBayesPrint ("   Citations                                                                     \n");
10037         MrBayesPrint ("                                                                                 \n");
10038         MrBayesPrint ("   This command shows a thorough list of citations you may consider using        \n");
10039         MrBayesPrint ("   when publishing the results of a MrBayes analysis.                            \n");
10040         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10041         }
10042     else if (!strcmp(helpTkn, "Showmatrix"))
10043         {
10044         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10045         MrBayesPrint ("   Showmatrix                                                                    \n");
10046         MrBayesPrint ("                                                                                 \n");
10047         MrBayesPrint ("   This command shows the character matrix currently in memory.                  \n");
10048         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10049         }
10050     else if (!strcmp(helpTkn, "Showbeagle"))
10051         {
10052         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10053         MrBayesPrint ("   Showbeagle                                                                    \n");
10054         MrBayesPrint ("                                                                                 \n");
10055         MrBayesPrint ("   This command shows available BEAGLE resources.                                \n");
10056         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10057         }
10058     else if (!strcmp(helpTkn, "Speciespartition"))
10059         {
10060         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10061         MrBayesPrint ("   Speciespartition                                                              \n");
10062         MrBayesPrint ("                                                                                 \n");
10063         MrBayesPrint ("   Defines a partition of tips into species. The format for the speciespartition \n");
10064         MrBayesPrint ("   command is                                                                    \n");
10065         MrBayesPrint ("                                                                                 \n");
10066         MrBayesPrint ("      Speciespartition <name> = <species name>:<taxon list> ,...,<sp nm>:<tx lst>\n");
10067         MrBayesPrint ("                                                                                 \n");
10068         MrBayesPrint ("   The command enumerates comma separated list of pairs consisting of 'species   \n");
10069         MrBayesPrint ("   name' and 'taxon list'. The 'taxon list' is a standard taxon list, as used by \n");
10070         MrBayesPrint ("   the 'Taxset' command. This means that you can use either the index or the name\n");
10071         MrBayesPrint ("   of a sequence ('taxon'). Ranges are specified using a dash, and a period can  \n");
10072         MrBayesPrint ("   be used as a synonym of the last sequence in the matrix.                      \n");
10073         MrBayesPrint ("                                                                                 \n");
10074         MrBayesPrint ("   For exammple: speciespartition species = SpeciesA: 1, SpeciesB: 2-.           \n");
10075         MrBayesPrint ("   Here, we name two species. SpeciesA is represented by a single sequence while \n");
10076         MrBayesPrint ("   SpeciesB is represented by all remaining sequences in the matrix.             \n");
10077         MrBayesPrint ("   Each sequence is specified by its row index in the data matrix.               \n");
10078         MrBayesPrint ("                                                                                 \n");
10079         MrBayesPrint ("   As with ordinary partitioning you may define multiple species partitioning    \n");
10080         MrBayesPrint ("   scheme. You have to use command 'set speciespartition' to enable use of one of\n");
10081         MrBayesPrint ("   them.                                                                         \n");
10082         MrBayesPrint ("                                                                                 \n");
10083         MrBayesPrint ("   Currently defined Speciespartitions:                                          \n");
10084         MrBayesPrint ("                                                                                 \n");
10085         MrBayesPrint ("   Number  Speciespartition name        Number of species                        \n");
10086         MrBayesPrint ("   --------------------------------------------------------------------------    \n");
10087         for (i=0; i<numDefinedSpeciespartitions; i++)
10088             {
10089             tempInt=0;
10090             for (j=0; j<numTaxa; j++)
10091                 {
10092                 if (tempInt < speciespartitionId[j][i])
10093                     tempInt = speciespartitionId[j][i];
10094                 }
10095             MrBayesPrint ("   %4d    %-24.24s   %4d",i+1, speciespartitionNames[i], tempInt);
10096             MrBayesPrint ("\n");
10097             }
10098         MrBayesPrint ("                                                                                \n");
10099         MrBayesPrint ("   --------------------------------------------------------------------------   \n");
10100         }
10101     else if (!strcmp(helpTkn, "Constraint"))
10102         {
10103         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10104         MrBayesPrint ("   Constraint                                                                    \n");
10105         MrBayesPrint ("                                                                                 \n");
10106         MrBayesPrint ("   This command defines a tree constraint. The format for the constraint         \n");
10107         MrBayesPrint ("   command is                                                                    \n");
10108         MrBayesPrint ("                                                                                 \n");
10109         MrBayesPrint ("      constraint <name> [hard|negative|partial] = <taxon list> [:<taxon list>]   \n");
10110         MrBayesPrint ("                                                                                 \n");
10111         MrBayesPrint ("   There are three types of constraint implemented in MrBayes. The type of the   \n");
10112         MrBayesPrint ("   constraint is specified by using one of the three keywords 'hard', 'negative',\n");
10113         MrBayesPrint ("   or 'partial' right after the name of the constraint. If no type is specified, \n");
10114         MrBayesPrint ("   then the constraint is assumed to be 'hard'.                                  \n");
10115         MrBayesPrint ("                                                                                 \n");
10116         MrBayesPrint ("   In a rooted tree, a 'hard' constraint forces the taxa in the list to form a   \n");
10117         MrBayesPrint ("   monophyletic group. In an unrooted tree, the taxon split that separates the   \n");
10118         MrBayesPrint ("   taxa in the list from other taxa is forced to be present. The interpretation  \n");
10119         MrBayesPrint ("   of this depends on whether the tree is rooted on a taxon outside the list or  \n");
10120         MrBayesPrint ("   a taxon in the list. If the outgroup is excluded , the taxa in the list are   \n");
10121         MrBayesPrint ("   assumed to form a monophyletic group, but if the outgroup is included, the    \n");
10122         MrBayesPrint ("   taxa that are not in the list are forced together.                            \n");
10123         MrBayesPrint ("                                                                                 \n");
10124         MrBayesPrint ("   A 'negative' constraint bans all the trees that have the listed taxa in the   \n");
10125         MrBayesPrint ("   same subtree. In other words, it is the opposite of a hard constraint.        \n");
10126         MrBayesPrint ("                                                                                 \n");
10127         MrBayesPrint ("   A 'partial' or backbone constraint is defined in terms of two sets of taxa    \n");
10128         MrBayesPrint ("   separated by a colon character. The constraint forces all taxa in the first   \n");
10129         MrBayesPrint ("   list to form a monophyletic group that does not include any taxon in the      \n");
10130         MrBayesPrint ("   second list. Taxa that are not included in either list can be placed in any   \n");
10131         MrBayesPrint ("   position on the tree, either inside or outside the constrained group. In an   \n");
10132         MrBayesPrint ("   unrooted tree, the two taxon lists can be switched with each other with no    \n");
10133         MrBayesPrint ("   effect. For a rooted tree, it is the taxa in the first list that have to be   \n");
10134         MrBayesPrint ("   monophyletic, that is, these taxa must share a common ancestor not shared with\n");
10135         MrBayesPrint ("   any taxon in the second list. The taxa in the second list may or may not fall \n");
10136         MrBayesPrint ("   in a monophyletic group depending on the rooting of the tree.                 \n");
10137         MrBayesPrint ("                                                                                 \n");
10138         MrBayesPrint ("   A list of taxa can be specified using a taxset, taxon names, taxon numbers, or\n");
10139         MrBayesPrint ("   any combination of the above, sepatated by spaces. The constraint is treated  \n");
10140         MrBayesPrint ("   as an absolute requirement of trees, that is, trees that are not compatible   \n");
10141         MrBayesPrint ("   with the constraint have zero prior (and hence zero posterior) probabilty.    \n");
10142         MrBayesPrint ("                                                                                 \n");
10143         MrBayesPrint ("   If you are interested in inferring ancestral states for a particular node,    \n");
10144         MrBayesPrint ("   you need to 'hard' constrain that node first using the 'constraint' command.  \n");
10145         MrBayesPrint ("   The same applies if you wish to calibrate an interior node in a dated         \n");
10146         MrBayesPrint ("   analysis. For more information on how to infer ancestral states, see the help \n");
10147         MrBayesPrint ("   for the 'report' command. For more on dating, see the 'calibrate' command.    \n");
10148         MrBayesPrint ("                                                                                 \n");
10149         MrBayesPrint ("   It is important to note that simply defining a constraint using this          \n");
10150         MrBayesPrint ("   command is not sufficient for the program to actually implement the           \n");
10151         MrBayesPrint ("   constraint in an analysis. You must also enforce the constraints using        \n");
10152         MrBayesPrint ("   'prset topologypr = constraints (<list of constraints>)'. For more infor-     \n");
10153         MrBayesPrint ("   mation on this, see the help on the 'prset' command.                          \n");
10154         MrBayesPrint ("                                                                                 \n");
10155         MrBayesPrint ("   Examples:                                                                     \n");
10156         MrBayesPrint ("                                                                                 \n");
10157         MrBayesPrint ("      constraint myclade = Homo Pan Gorilla                                      \n");
10158         MrBayesPrint ("                                                                                 \n");
10159         MrBayesPrint ("   Defines a hard constraint forcing Homo, Pan, and Gorilla to form a mono-      \n");
10160         MrBayesPrint ("   phyletic group or a split that does not include any other taxa.               \n");
10161         MrBayesPrint ("                                                                                 \n");
10162         MrBayesPrint ("      constraint forbiddenclade negative = Homo Pan Gorilla                      \n");
10163         MrBayesPrint ("                                                                                 \n");
10164         MrBayesPrint ("   Defines a negative constraint that associates all trees where Homon, Pan, and \n");
10165         MrBayesPrint ("   Gorilla form a monophyletic group with zero posterior probability. In other   \n");
10166         MrBayesPrint ("   words, such trees will not be sampled during MCMC.                            \n");
10167         MrBayesPrint ("                                                                                 \n");
10168         MrBayesPrint ("      constraint backbone partial = Homo Gorilla : Mus                           \n");
10169         MrBayesPrint ("                                                                                 \n");
10170         MrBayesPrint ("   Defines a partial constraint that keeps Mus outside of the clade defined by   \n");
10171         MrBayesPrint ("   the most recent common ancestor of Homo and Gorilla. Other taxa are allowed to\n");
10172         MrBayesPrint ("   sit anywhere in the tree. Note that this particular constraint is meaningless \n");
10173         MrBayesPrint ("   in unrooted trees. MrBayes does not assume anything about the position of the \n");
10174         MrBayesPrint ("   outgroup unless it is explicitly included in the partial constraint. Therefore\n");
10175         MrBayesPrint ("   a partial constraint must have at least two taxa on each side of the ':' to be\n");
10176         MrBayesPrint ("   useful in analyses of unrooted trees. The case is different for rooted trees, \n");
10177         MrBayesPrint ("   where it is sufficient for a partial constraint to have more than one taxon   \n");
10178         MrBayesPrint ("   before the ':', as in the example given above, to constrain tree space.       \n");
10179         MrBayesPrint ("                                                                                 \n");
10180         MrBayesPrint ("   To define a more complex constraint tree, simply combine constraints into a   \n");
10181         MrBayesPrint ("   list when issuing the 'prset topologypr' command.                             \n");
10182         MrBayesPrint ("                                                                                 \n");
10183         if (numDefinedConstraints > 0)
10184             {
10185             MrBayesPrint ("   Currently defined constraints:                                                \n");
10186             MrBayesPrint ("                                                                                 \n");
10187             MrBayesPrint ("   Number  Constraint name          type      Number of taxa in[:out]            \n");
10188             MrBayesPrint ("   --------------------------------------------------------------------------    \n");
10189             }
10190         for (i=0; i<numDefinedConstraints; i++)
10191             {
10192             strncpy (tempString, constraintNames[i], 22);
10193             MrBayesPrint ("   %4d    %-22.22s   ",i+1, tempString);
10194             if (definedConstraintsType[i] == HARD)
10195                 MrBayesPrint ("hard      ");
10196             else if (definedConstraintsType[i] == PARTIAL)
10197                 MrBayesPrint ("partial   ");
10198             else
10199                 {
10200                 assert (definedConstraintsType[i] == NEGATIVE);
10201                 MrBayesPrint ("negative  ");
10202                 }
10203             k = NumBits (definedConstraint[i], numTaxa/nBitsInALong + 1);
10204             MrBayesPrint ("%d", k);
10205             if (definedConstraintsType[i] == PARTIAL)
10206                 {
10207                 k = NumBits (definedConstraintTwo[i], numTaxa/nBitsInALong + 1);
10208                 MrBayesPrint (":%d", k);
10209                 }
10210             MrBayesPrint ("\n");
10211             }
10212         MrBayesPrint ("                                                                                \n");
10213         MrBayesPrint ("   --------------------------------------------------------------------------   \n");
10214         }
10215     else if (!strcmp(helpTkn, "Calibrate"))
10216         {
10217         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10218         MrBayesPrint ("   Calibrate                                                                     \n");
10219         MrBayesPrint ("                                                                                 \n");
10220         MrBayesPrint ("   This command dates a terminal or interior node in the tree. The format is     \n");
10221         MrBayesPrint ("                                                                                 \n");
10222         MrBayesPrint ("      calibrate <node_name> = <age_prior>                                        \n");
10223         MrBayesPrint ("                                                                                 \n");
10224         MrBayesPrint ("   where <node_name> is the name of a defined interior constraint node or the    \n");
10225         MrBayesPrint ("   name of a terminal node (tip) and <age_prior> is a prior probability distribu-\n");
10226         MrBayesPrint ("   tion on the age of the node. The latter can either be a fixed date or a date  \n");
10227         MrBayesPrint ("   drawn from one of the available prior probability distributions. In general,  \n");
10228         MrBayesPrint ("   the available prior probability distributions are parameterized in terms of   \n");
10229         MrBayesPrint ("   the expected mean age of the distribution to facilitate for users. Some dis-  \n");
10230         MrBayesPrint ("   tributions put a positive probability on all ages above 0.0, while others in- \n");
10231         MrBayesPrint ("   clude a minimum-age constraint and sometimes a maximum-age constraint. The    \n");
10232         MrBayesPrint ("   available distributions and their parameters are:                             \n");
10233         MrBayesPrint ("                                                                                 \n");
10234         MrBayesPrint ("      calibrate <node_name> = fixed(<age>)                                       \n");
10235         MrBayesPrint ("      calibrate <node_name> = uniform(<min_age>,<max_age>)                       \n");
10236         MrBayesPrint ("      calibrate <node_name> = offsetexponential(<min_age>,<mean_age>)            \n");
10237         MrBayesPrint ("      calibrate <node_name> = truncatednormal(<min_age>,<mean_age>,<stdev>)      \n");
10238         MrBayesPrint ("      calibrate <node_name> = lognormal(<mean_age>,<stdev>)                      \n");
10239         MrBayesPrint ("      calibrate <node_name> = offsetlognormal(<min_age>,<mean_age>,<stdev>)      \n");
10240         MrBayesPrint ("      calibrate <node_name> = gamma(<mean_age>,<stdev>)                          \n");
10241         MrBayesPrint ("      calibrate <node_name> = offsetgamma(<min_age>,<mean_age>,<stdev>)          \n");
10242         MrBayesPrint ("                                                                                 \n");
10243         MrBayesPrint ("   Note that mean_age is always the mean age and stdev the standard deviation of \n");
10244         MrBayesPrint ("   the distribution measured in user-defined time units. This way of specifying  \n");
10245         MrBayesPrint ("   the distribution parameters is often different from the parameterization used \n");
10246         MrBayesPrint ("   elsewhere in the program. For instance, the standard parameters of the gamma  \n");
10247         MrBayesPrint ("   distribution used by MrBayes are shape (alpha) and rate (beta). If you want   \n");
10248         MrBayesPrint ("   to use the standard parameterization, the conversions are as follows:         \n");
10249         MrBayesPrint ("                                                                                 \n");
10250         MrBayesPrint ("      exponential distributon: mean    = 1 / rate                                \n");
10251         MrBayesPrint ("      gamma distributon:       mean    = alpha / beta                            \n");
10252         MrBayesPrint ("                               st.dev. = square_root (alpha / beta^2)            \n");
10253         MrBayesPrint ("      lognormal distributon:   mean    = exp (mean_log + st.dev._log^2/2)        \n");
10254         MrBayesPrint ("                               st.dev. = square_root ((exp (st.dev._log^2) - 1)  \n");
10255         MrBayesPrint ("                                         * (exp (2*mean_log + st.dev._log^2))    \n");
10256         MrBayesPrint ("                                                                                 \n");
10257         MrBayesPrint ("   The truncated normal distribution is an exception in that the mean_age and    \n");
10258         MrBayesPrint ("   stdev parameters are the mean and standard deviation of the underlying non-   \n");
10259         MrBayesPrint ("   truncated normal distribution. The truncation will cause the modified distri- \n");
10260         MrBayesPrint ("   bution to have a higher mean and lower standard deviation. The magnitude of   \n");
10261         MrBayesPrint ("   that effect depends on how much of the tail of the distribution is removed.   \n");
10262         MrBayesPrint ("                                                                                 \n");
10263         MrBayesPrint ("   Note that previous to version 3.2.2, MrBayes used the standard rate parameter-\n");
10264         MrBayesPrint ("   ization of the offset exponential. This should not cause a problem in most    \n");
10265         MrBayesPrint ("   cases because the old parameterization will result in an error in more recent \n");
10266         MrBayesPrint ("   versions of MrBayes, and the likely source of the error is given in the error \n");
10267         MrBayesPrint ("   message.                                                                      \n");
10268         MrBayesPrint ("                                                                                 \n");
10269         MrBayesPrint ("   For a practical example, assume that we had three fossil terminals named      \n");
10270         MrBayesPrint ("   'FossilA', 'FossilB', and 'FossilC'. Assume further that we want to fix the   \n");
10271         MrBayesPrint ("   age of FossilA to 100.0 million years, we think that FossilB is somewhere     \n");
10272         MrBayesPrint ("   between 100.0 and 200.0 million years old, and that FossilC is at least 300.0 \n");
10273         MrBayesPrint ("   million years old, possibly older but relatively unlikely to be more than     \n");
10274         MrBayesPrint ("   400.0 million years old. Then we might use the commands:                      \n");
10275         MrBayesPrint ("                                                                                 \n");
10276         MrBayesPrint ("      calibrate FossilA = fixed(100) FossilB = uniform(100,200)                  \n");
10277         MrBayesPrint ("      calibrate FossilC = offsetexponential(300,400)                             \n");
10278         MrBayesPrint ("                                                                                 \n");
10279         MrBayesPrint ("   Note that it is possible to give more than one calibration for each           \n");
10280         MrBayesPrint ("   'calibrate' statement. Thus, 'calibrate FossilA=<setting> FossilB=<setting>'  \n");
10281         MrBayesPrint ("   would be a valid statement.                                                   \n");
10282         MrBayesPrint ("                                                                                 \n");
10283         MrBayesPrint ("   To actually use the calibrations to obtain dated trees, you also need to set  \n");
10284         MrBayesPrint ("   a clock model using relevant 'brlenspr' and 'nodeagepr' options of the 'prset'\n");
10285         MrBayesPrint ("   command. You may also want to examine the 'clockvarpr' and 'clockratepr' op-  \n");
10286         MrBayesPrint ("   tions. Furthermore, you need to activate the relevant constraint(s) using     \n");
10287         MrBayesPrint ("   'topologypr', if you use any dated interior nodes in the tree.                \n");
10288         MrBayesPrint ("                                                                                 \n");
10289         MrBayesPrint ("   You may wish to remove a calibration from an interior or terminal node, which \n");
10290         MrBayesPrint ("   has previously been calibrated. You can do that using                         \n");
10291         MrBayesPrint ("                                                                                 \n");
10292         MrBayesPrint ("      calibrate <node_name> = unconstrained                                      \n");
10293         MrBayesPrint ("                                                                                 \n");
10294         j = 0;
10295         for (i=0; i<numTaxa; i++)
10296             if (tipCalibration[i].prior != unconstrained)
10297                 j++;
10298         for (i=0; i<numDefinedConstraints; i++)
10299             if (nodeCalibration[i].prior != unconstrained)
10300                 j++;
10301         if (j > 0)
10302             {
10303             MrBayesPrint ("                                                                                 \n");
10304             MrBayesPrint ("   Currently defined calibrations:                                               \n");
10305             MrBayesPrint ("                                                                                 \n");
10306             MrBayesPrint ("   Node name                Type       Calibration                               \n");
10307             MrBayesPrint ("   ------------------------------------------------------------------            \n");
10308             for (i=0; i<numTaxa+numDefinedConstraints; i++)
10309                 {
10310                 if (i<numTaxa)
10311                     calibrationPtr = &tipCalibration[i];
10312                 else
10313                     calibrationPtr = &nodeCalibration[i-numTaxa];
10314                 if (calibrationPtr != NULL && calibrationPtr->prior != unconstrained)
10315                     {
10316                     if (i<numTaxa)
10317                         strncpy (tempString, taxaNames[i], 22);
10318                     else
10319                         strncpy (tempString, constraintNames[i-numTaxa], 22);
10320                     if (i<numTaxa)
10321                         MrBayesPrint ("   %-22.22s   Terminal   %s\n", tempString, calibrationPtr->name);
10322                     else
10323                         MrBayesPrint ("   %-22.22s   Interior   %s\n", tempString, calibrationPtr->name);
10324                     }
10325                 }
10326             }
10327         MrBayesPrint ("                                                                                 \n");
10328         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10329         }
10330     else if (!strcmp(helpTkn, "Showmodel"))
10331         {
10332         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10333         MrBayesPrint ("   Showmodel                                                                     \n");
10334         MrBayesPrint ("                                                                                 \n");
10335         MrBayesPrint ("   This command shows the current model settings. The correct usage is           \n");
10336         MrBayesPrint ("                                                                                 \n");
10337         MrBayesPrint ("      showmodel                                                                  \n");
10338         MrBayesPrint ("                                                                                 \n");
10339         MrBayesPrint ("   After typing \"showmodel\", the modelling assumptions are shown on a          \n");
10340         MrBayesPrint ("   partition-by-partition basis.                                                 \n");
10341         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10342         }
10343     else if (!strcmp(helpTkn, "Execute"))
10344         {
10345         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10346         MrBayesPrint ("   Execute                                                                       \n");
10347         MrBayesPrint ("                                                                                 \n");
10348         MrBayesPrint ("   This command executes a file called <file name>. The correct usage is:        \n");
10349         MrBayesPrint ("                                                                                 \n");
10350         MrBayesPrint ("      execute <file name>                                                        \n");
10351         MrBayesPrint ("                                                                                 \n");
10352         MrBayesPrint ("   For example,                                                                  \n");
10353         MrBayesPrint ("                                                                                 \n");
10354         MrBayesPrint ("      execute replicase.nex                                                      \n");
10355         MrBayesPrint ("                                                                                 \n");
10356         MrBayesPrint ("   would execute the file named \"replicase.nex\". This file must be in the      \n");
10357         MrBayesPrint ("   same directory as the executable.                                             \n");
10358         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10359         }
10360     else if (!strcmp(helpTkn, "Lset"))
10361         {
10362         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10363         MrBayesPrint ("   Lset                                                                          \n");
10364         MrBayesPrint ("                                                                                 \n");
10365         MrBayesPrint ("   This command sets the parameters of the likelihood model. The likelihood      \n");
10366         MrBayesPrint ("   function is the probability of observing the data conditional on the phylo-   \n");
10367         MrBayesPrint ("   genetic model. In order to calculate the likelihood, you must assume a        \n");
10368         MrBayesPrint ("   model of character change. This command lets you tailor the biological        \n");
10369         MrBayesPrint ("   assumptions made in the phylogenetic model. The correct usage is              \n");
10370         MrBayesPrint ("                                                                                 \n");
10371         MrBayesPrint ("      lset <parameter>=<option> ... <parameter>=<option>                         \n");
10372         MrBayesPrint ("                                                                                 \n");
10373         MrBayesPrint ("   For example, \"lset nst=6 rates=gamma\" would set the model to a general      \n");
10374         MrBayesPrint ("   model of DNA substition (the GTR) with gamma-distributed rate variation       \n");
10375         MrBayesPrint ("   across sites.                                                                 \n");
10376         MrBayesPrint ("                                                                                 \n");
10377         MrBayesPrint ("   Options:                                                                      \n");
10378         MrBayesPrint ("                                                                                 \n");
10379         MrBayesPrint ("   Applyto   -- This option allows you to apply the lset commands to specific    \n");
10380         MrBayesPrint ("                partitions. This command should be the first in the list of      \n");
10381         MrBayesPrint ("                commands specified in lset. Moreover, it only makes sense to     \n");
10382         MrBayesPrint ("                be using this command if the data have been partitioned. A       \n");
10383         MrBayesPrint ("                default partition is set on execution of a matrix. If the data   \n");
10384         MrBayesPrint ("                are homogeneous (i.e., all of the same data type), then this     \n");
10385         MrBayesPrint ("                partition will not subdivide the characters. Up to 30 other      \n");
10386         MrBayesPrint ("                partitions can be defined, and you can switch among them using   \n");
10387         MrBayesPrint ("                \"set partition=<partition name>\". Now, you may want to         \n");
10388         MrBayesPrint ("                specify different models to different partitions of the data.    \n");
10389         MrBayesPrint ("                Applyto allows you to do this. For example, say you have         \n");
10390         MrBayesPrint ("                partitioned the data by codon position, and you want to apply    \n");
10391         MrBayesPrint ("                a nst=2 model to the first two partitions and nst=6 to the       \n");
10392         MrBayesPrint ("                last. This could be implemented in two uses of lset:             \n");
10393         MrBayesPrint ("                                                                                 \n");
10394         MrBayesPrint ("                   lset applyto=(1,2) nst=2                                      \n");
10395         MrBayesPrint ("                                                                                 \n");
10396         MrBayesPrint ("                   lset applyto=(3) nst=6                                        \n");
10397         MrBayesPrint ("                                                                                 \n");
10398         MrBayesPrint ("                The first applies the parameters after \"applyto\" to the        \n");
10399         MrBayesPrint ("                first and second partitions. The second lset applies nst=6       \n");
10400         MrBayesPrint ("                to the third partition. You can also use applyto=(all), which    \n");
10401         MrBayesPrint ("                attempts to apply the parameter settings to all of the data      \n");
10402         MrBayesPrint ("                partitions. Importantly, if the option is not consistent with    \n");
10403         MrBayesPrint ("                the data in the partition, the program will not apply the        \n");
10404         MrBayesPrint ("                lset option to that partition.                                   \n");
10405         MrBayesPrint ("   Nucmodel  -- This specifies the general form of the nucleotide substitution   \n");
10406         MrBayesPrint ("                model. The options are \"4by4\" [the standard model of DNA       \n");
10407         MrBayesPrint ("                substitution in which there are only four states (A,C,G,T/U)],   \n");
10408         MrBayesPrint ("                \"doublet\" (a model appropriate for modelling the stem regions  \n");
10409         MrBayesPrint ("                of ribosomal genes where the state space is the 16 doublets of   \n");
10410         MrBayesPrint ("                nucleotides), \"codon\" (the substitution model is expanded      \n");
10411         MrBayesPrint ("                around triplets of nucleotides--a codon), and \"Protein\"        \n");
10412         MrBayesPrint ("                (triplets of nucleotides are translated to amino acids, which    \n");
10413         MrBayesPrint ("                form the basis of the substitution model).                       \n");
10414         MrBayesPrint ("   Nst       -- Sets the number of substitution types: \"1\" constrains all of   \n");
10415         MrBayesPrint ("                the rates to be the same (e.g., a JC69 or F81 model); \"2\" all- \n");
10416         MrBayesPrint ("                ows transitions and transversions to have potentially different  \n");
10417         MrBayesPrint ("                rates (e.g., a K80 or HKY85 model); \"6\" allows all rates to    \n");
10418         MrBayesPrint ("                be different, subject to the constraint of time-reversibility    \n");
10419         MrBayesPrint ("                (e.g., a GTR model). Finally, 'nst' can be set to 'mixed', which \n");
10420         MrBayesPrint ("                results in the Markov chain sampling over the space of all poss- \n");
10421         MrBayesPrint ("                ible reversible substitution models, including the GTR model and \n");
10422         MrBayesPrint ("                all models that can be derived from it model by grouping the six \n");
10423         MrBayesPrint ("                rates in various combinations. This includes all the named models\n");
10424         MrBayesPrint ("                above and a large number of others, with or without name.        \n");
10425         MrBayesPrint ("   Code      -- Enforces the use of a particular genetic code. The default       \n");
10426         MrBayesPrint ("                is the universal code. Other options include \"vertmt\" for      \n");
10427         MrBayesPrint ("                vertebrate mitocondrial, \"invermt\", \"mycoplasma\", \"yeast\", \n");
10428         MrBayesPrint ("                \"ciliate\", \"echinoderm\", \"euplotid\", and \"metmt\" (for    \n");
10429         MrBayesPrint ("                metazoan mitochondrial except vertebrates).                      \n");
10430         MrBayesPrint ("   Ploidy    -- Specifies the ploidy of the organism. Options are \"Haploid\",   \n");
10431         MrBayesPrint ("                \"Diploid\" or \"Zlinked\". This option is used when a coalescent\n");
10432         MrBayesPrint ("                prior is used on trees.                                          \n");
10433         MrBayesPrint ("   Rates     -- Sets the model for among-site rate variation. In general, the    \n");
10434         MrBayesPrint ("                rate at a site is considered to be an unknown random variable.   \n");
10435         MrBayesPrint ("                The valid options are:                                           \n");
10436         MrBayesPrint ("                * equal    -- No rate variation across sites.                    \n");
10437         MrBayesPrint ("                * gamma    -- Gamma-distributed rates across sites. The rate     \n");
10438         MrBayesPrint ("                              at a site is drawn from a gamma distribution.      \n");
10439         MrBayesPrint ("                              The gamma distribution has a single parameter      \n");
10440         MrBayesPrint ("                              that describes how much rates vary.                \n");
10441         MrBayesPrint ("                * lnorm    -- Lognormal-distributed rates across sites. The      \n");
10442         MrBayesPrint ("                              rate at a site is drawn from a lognormal           \n");
10443         MrBayesPrint ("                              distribution. the lognormal distribiton has a      \n");
10444         MrBayesPrint ("                              single parameter, sigma (SD) that describes how    \n");
10445         MrBayesPrint ("                              much rates vary (mean fixed to log(1.0) == 0.0.    \n");
10446         MrBayesPrint ("                * adgamma  -- Autocorrelated rates across sites. The marg-       \n");
10447         MrBayesPrint ("                              inal rate distribution is gamma, but adjacent      \n");
10448         MrBayesPrint ("                              sites have correlated rates.                       \n");
10449         MrBayesPrint ("                * propinv  -- A proportion of the sites are invariable.          \n");
10450         MrBayesPrint ("                * invgamma -- A proportion of the sites are invariable while     \n");
10451         MrBayesPrint ("                              the rate for the remaining sites are drawn from    \n");
10452         MrBayesPrint ("                              a gamma distribution.                              \n");
10453         MrBayesPrint ("                * kmixture -- Site rates come from a mixture with k categories.  \n");
10454         MrBayesPrint ("                              Category rates are drawn from an ordered flat      \n");
10455         MrBayesPrint ("                              Dirichlet distribution with mean rather than sum   \n");
10456         MrBayesPrint ("                              equal to 1.0.                                      \n");
10457         MrBayesPrint ("                Note that MrBayes versions 2.0 and earlier supported options     \n");
10458         MrBayesPrint ("                that allowed site specific rates (e.g., ssgamma). In versions    \n");
10459         MrBayesPrint ("                3.0 and later, site specific rates are allowed, but set using    \n");
10460         MrBayesPrint ("                the 'prset ratepr' command for each partition.                   \n");
10461         MrBayesPrint ("   Ngammacat -- Sets the number of rate categories for the gamma distribution.   \n");
10462         MrBayesPrint ("                The gamma distribution is continuous. However, it is virtually   \n");
10463         MrBayesPrint ("                impossible to calculate likelihoods under the continuous gamma   \n");
10464         MrBayesPrint ("                distribution. Hence, an approximation to the continuous gamma    \n");
10465         MrBayesPrint ("                is used; the gamma distribution is broken into ncat categories   \n");
10466         MrBayesPrint ("                of equal weight (1/ncat). The mean rate for each category rep-   \n");
10467         MrBayesPrint ("                resents the rate for the entire cateogry. This option allows     \n");
10468         MrBayesPrint ("                you to specify how many rate categories to use when approx-      \n");
10469         MrBayesPrint ("                imating the gamma. The approximation is better as ncat is inc-   \n");
10470         MrBayesPrint ("                reased. In practice, \"ncat=4\" does a reasonable job of         \n");
10471         MrBayesPrint ("                approximating the continuous gamma.                              \n");
10472         MrBayesPrint ("   Nlnormcat -- Used to set the number of discrete categories used for the ap-   \n");
10473         MrBayesPrint ("                proximation of the lognormal distribution, in the same way as    \n");
10474         MrBayesPrint ("                the Ngammacat setting for the discrete gamma approximation.      \n");
10475         MrBayesPrint ("                Default value is 4.                                              \n");
10476         MrBayesPrint ("   Nmixtcat  -- Used to set the number of components in the k-mixture model of   \n");
10477         MrBayesPrint ("                rate variation across sites. Default value is 4.                 \n");
10478 #if 0
10479         /* Temporarily disable this because of conflict with likelihood calculators. It should be renamed to samplerates when reintroduced. */
10480         MrBayesPrint ("   Usegibbs  -- Specifies whether site probabilities under the discrete gamma    \n");
10481         MrBayesPrint ("                model of rate variation across sites will be summed across rate  \n");
10482         MrBayesPrint ("                categories ('Usegibbs=No') or sampled using a Gibbs sampler      \n");
10483         MrBayesPrint ("                ('Usegibbs=Yes'). The Gibbs sampling approach is much faster and \n");
10484         MrBayesPrint ("                requires less memory but the likelihood of the sampled points    \n");
10485         MrBayesPrint ("                will be considerably higher than with the standard approach of   \n");
10486         MrBayesPrint ("                summing probabilities, so you need to be aware of this when com- \n");
10487         MrBayesPrint ("                paring your results with those you obtain with other programs.   \n");
10488         MrBayesPrint ("                Assume that you are using n rate categories in your discrete     \n");
10489         MrBayesPrint ("                gamma distribution. Then the Gibbs approach is up to n times     \n");
10490         MrBayesPrint ("                faster and requires 1/n as much memory as the standard method.   \n");
10491         MrBayesPrint ("                Unfortunately, the state space also becomes larger so the chain  \n");
10492         MrBayesPrint ("                may need more time to converge. The approach should work best    \n");
10493         MrBayesPrint ("                for large trees, where the uncertainty concerning the best rate  \n");
10494         MrBayesPrint ("                category for each site is negligible. Gibbs sampling cannot be   \n");
10495         MrBayesPrint ("                used for the autocorrelated discrete gamma model, for standard   \n");
10496         MrBayesPrint ("                data, or for restriction data. Also, MrBayes will not use Gibbs  \n");
10497         MrBayesPrint ("                sampling when you want to infer site rates.                      \n");
10498         MrBayesPrint ("   Gibbsfreq -- Sets the frequency with which the rate categories of the discrete\n");
10499         MrBayesPrint ("                gamma will be Gibbs sampled. In practice, we have found that a   \n");
10500         MrBayesPrint ("                resampling frequency of every 100 MCMC generations works well for\n");
10501         MrBayesPrint ("                reasonably long runs. The more frequent the Gibbs sampling, the  \n");
10502         MrBayesPrint ("                slower the Gibbs sampling approach will be. If you have k rate   \n");
10503         MrBayesPrint ("                categories and Gibbs sample them every n generations, then the   \n");
10504         MrBayesPrint ("                time it takes to complete n generations will roughly be propor-  \n");
10505         MrBayesPrint ("                tional to n+k. Compare this with the traditional approach of     \n");
10506         MrBayesPrint ("                summing across the n rate categories in every generation, which  \n");
10507         MrBayesPrint ("                requires time proportional to n*k. In practice, however, the     \n");
10508         MrBayesPrint ("                speed difference is not quite as large as this.                  \n");
10509 #endif
10510         MrBayesPrint ("   Nbetacat  -- Sets the number of rate categories for the beta distribution.    \n");
10511         MrBayesPrint ("                A symmetric beta distribution is used to model the stationary    \n");
10512         MrBayesPrint ("                frequencies when morphological data are used. This option        \n");
10513         MrBayesPrint ("                specifies how well the beta distribution will be approximated.   \n");
10514         MrBayesPrint ("   Omegavar  -- Allows the nonsynonymous/synonymous rate ratio (omega) to vary   \n");
10515         MrBayesPrint ("                across codons. Ny98 assumes that there are three classes, with   \n");
10516         MrBayesPrint ("                potentially different omega values (omega1, omega2, omega3):     \n");
10517         MrBayesPrint ("                omega2 = 1; 0 < omega1 < 1; and omega3 > 1. Like the Ny98 model, \n");
10518         MrBayesPrint ("                the M3 model has three omega classes. However, their values are  \n");
10519         MrBayesPrint ("                less constrained, with omega1 < omega2 < omega3. The default     \n");
10520         MrBayesPrint ("                (omegavar = equal) has no variation on omega across sites.       \n");
10521         MrBayesPrint ("   Covarion  -- This forces the use of a covarion-like model of substitution     \n");
10522         MrBayesPrint ("                for nucleotide or amino acid data. The valid options are \"yes\" \n");
10523         MrBayesPrint ("                and \"no\". The covarion model allows the rate at a site to      \n");
10524         MrBayesPrint ("                change over its evolutionary history. Specifically, the site     \n");
10525         MrBayesPrint ("                is either on or off. When it is off, no substitutions are poss-  \n");
10526         MrBayesPrint ("                ible. When the process is on, substitutions occur according to   \n");
10527         MrBayesPrint ("                a specified substitution model (specified using the other        \n");
10528         MrBayesPrint ("                lset options).                                                   \n");
10529         MrBayesPrint ("   Coding    -- This specifies how characters were sampled. If all site patterns \n");
10530         MrBayesPrint ("                had the possibility of being sampled, then \"All\" should be     \n");
10531         MrBayesPrint ("                specified (the default). Otherwise \"Variable\" (only variable   \n");
10532         MrBayesPrint ("                characters had the possibility of being sampled), \"Informative\"\n");
10533         MrBayesPrint ("                (only parsimony informative characters has the possibility of    \n");
10534         MrBayesPrint ("                being sampled), \"Nosingletons\" (characters which are constant  \n");
10535         MrBayesPrint ("                in all but one taxon were not sampled), \"Noabsencesites\" (char-\n");
10536         MrBayesPrint ("                acters for which all taxa were coded as absent were not sampled),\n");
10537         MrBayesPrint ("                \"Nopresencesites\" (characters for which all taxa were coded as \n");
10538         MrBayesPrint ("                present were not sampled). \"All\" works for all data types.     \n");
10539         MrBayesPrint ("                However, the others only work for morphological (All/Variable/   \n");
10540         MrBayesPrint ("                Informative/Nosingletons) or restriction site (All/Variable/     \n");
10541         MrBayesPrint ("                Informative/Nosingletons/Noabsencesites/Nopresencesites/         \n");
10542         MrBayesPrint ("                Nosingletonpresence/Nosingletonabsence) data.                    \n");
10543         MrBayesPrint ("   Parsmodel -- This forces calculation under the so-called parsimony model      \n");
10544         MrBayesPrint ("                described by Tuffley and Steel (1998). The options are \"yes\"   \n");
10545         MrBayesPrint ("                or \"no\". Note that the biological assumptions of this model    \n");
10546         MrBayesPrint ("                are anything but parsimonious. In fact, this model assumes many  \n");
10547         MrBayesPrint ("                more parameters than the next most complicated model implemented \n");
10548         MrBayesPrint ("                in this program. If you really believe that the parsimony model  \n");
10549         MrBayesPrint ("                makes the biological assumptions described by Tuffley and Steel, \n");
10550         MrBayesPrint ("                then the parsimony method is miss-named.                         \n");
10551     /*  MrBayesPrint ("   Augment   -- This allows the chain to consider the missing entries of         \n");
10552         MrBayesPrint ("                the data matrix as random variables. A Gibbs sampler is          \n");
10553         MrBayesPrint ("                used to sample states.                                           \n"); */
10554         MrBayesPrint ("                                                                                 \n");
10555         if (numCurrentDivisions == 0)
10556             tempInt = 1;
10557         else
10558             tempInt = numCurrentDivisions;
10559         for (i=0; i<tempInt; i++)
10560             {
10561             if (numCurrentDivisions == 0)
10562                 {
10563                 MrBayesPrint ("   Default model settings:                                                       \n");
10564                 mp = &defaultModel;
10565                 }
10566             else
10567                 {
10568                 MrBayesPrint ("   Model settings for partition %d:                                              \n", i+1);
10569                 mp = &modelParams[i];
10570                 }
10571             MrBayesPrint ("                                                                                 \n");
10572             MrBayesPrint ("   Parameter    Options                               Current Setting            \n");
10573             MrBayesPrint ("   ------------------------------------------------------------------            \n");
10574             MrBayesPrint ("   Nucmodel     4by4/Doublet/Codon/Protein              %s                       \n", mp->nucModel);
10575             MrBayesPrint ("   Nst          1/2/6/Mixed                             %s                       \n", mp->nst);
10576             MrBayesPrint ("   Code         Universal/Vertmt/Invermt/Yeast/Mycoplasma/                       \n");
10577             MrBayesPrint ("                Ciliate/Echinoderm/Euplotid/Metmt       %s                       \n", mp->geneticCode);
10578             MrBayesPrint ("   Ploidy       Haploid/Diploid/Zlinked                 %s                       \n", mp->ploidy);
10579             MrBayesPrint ("   Rates        Equal/Gamma/LNorm/Propinv/                                       \n");
10580             MrBayesPrint ("                Invgamma/Adgamma/Kmixture               %s                       \n", mp->ratesModel);
10581             MrBayesPrint ("   Ngammacat    <number>                                %d                       \n", mp->numGammaCats);
10582             MrBayesPrint ("   Nlnormcat    <number>                                %d                       \n", mp->numLnormCats);
10583             MrBayesPrint ("   Nmixtcat     <number>                                %d                       \n", mp->numMixtCats);
10584 #if 0
10585 /* Temporarily disable this because of conflict with likelihood calculators. It should be renamed to samplerates when reintroduced. */
10586             MrBayesPrint ("   Usegibbs     Yes/No                                  %s                       \n", mp->useGibbs);
10587             MrBayesPrint ("   Gibbsfreq    <number>                                %d                       \n", mp->gibbsFreq);
10588 #endif
10589             MrBayesPrint ("   Nbetacat     <number>                                %d                       \n", mp->numBetaCats);
10590             MrBayesPrint ("   Omegavar     Equal/Ny98/M3                           %s                       \n", mp->omegaVar);
10591             MrBayesPrint ("   Covarion     No/Yes                                  %s                       \n", mp->covarionModel);
10592             MrBayesPrint ("   Coding       All/Variable/Informative/Nosingletons                            \n");
10593             MrBayesPrint ("                Noabsencesites/Nopresencesites/                                  \n");
10594             MrBayesPrint ("                Nosingletonabsence/Nosingletonpresence  %s                       \n", mp->codingString);
10595             MrBayesPrint ("   Parsmodel    No/Yes                                  %s                       \n", mp->parsModel);
10596         /*  MrBayesPrint ("   Augment      No/Yes                                  %s                       \n", mp->augmentData); */
10597             MrBayesPrint ("                                                                                 \n");
10598             MrBayesPrint ("   ------------------------------------------------------------------            \n");
10599             }
10600         }
10601     else if (!strcmp(helpTkn, "Prset"))
10602         {
10603         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10604         MrBayesPrint ("   Prset                                                                         \n");
10605         MrBayesPrint ("                                                                                 \n");
10606         MrBayesPrint ("   This command sets the priors for the phylogenetic model. Remember that        \n");
10607         MrBayesPrint ("   in a Bayesian analysis, you must specify a prior probability distribution     \n");
10608         MrBayesPrint ("   for the parameters of the likelihood model. The prior distribution rep-       \n");
10609         MrBayesPrint ("   resents your prior beliefs about the parameter before observation of the      \n");
10610         MrBayesPrint ("   data. This command allows you to tailor your prior assumptions to a large     \n");
10611         MrBayesPrint ("   extent.                                                                       \n");
10612         MrBayesPrint ("                                                                                 \n");
10613         MrBayesPrint ("   Options:                                                                      \n");
10614         MrBayesPrint ("                                                                                 \n");
10615         MrBayesPrint ("   Applyto       -- This option allows you to apply the prset commands to        \n");
10616         MrBayesPrint ("                    specific partitions. This command should be the first        \n");
10617         MrBayesPrint ("                    in the list of commands specified in prset. Moreover, it     \n");
10618         MrBayesPrint ("                    only makes sense to be using this command if the data        \n");
10619         MrBayesPrint ("                    have been partitioned. A default partition is set on         \n");
10620         MrBayesPrint ("                    execution of a matrix. If the data are homogeneous           \n");
10621         MrBayesPrint ("                    (i.e., all of the same data type), then this partition       \n");
10622         MrBayesPrint ("                    will not subdivide the characters. Up to 30 other part-      \n");
10623         MrBayesPrint ("                    itions can be defined, and you can switch among them using   \n");
10624         MrBayesPrint ("                    \"set partition=<partition name>\". Now, you may want to     \n");
10625         MrBayesPrint ("                    specify different priors to different partitions of the      \n");
10626         MrBayesPrint ("                    data. Applyto allows you to do this. For example, say        \n");
10627         MrBayesPrint ("                    you have partitioned the data by codon position, and         \n");
10628         MrBayesPrint ("                    you want to fix the statefreqs to equal for the first two    \n");
10629         MrBayesPrint ("                    partitions but apply a flat Dirichlet prior to the state-    \n");
10630         MrBayesPrint ("                    freqs of the last. This could be implemented in two uses of  \n");
10631         MrBayesPrint ("                    prset:                                                       \n");
10632         MrBayesPrint ("                                                                                 \n");
10633         MrBayesPrint ("                       prset applyto=(1,2) statefreqs=fixed(equal)               \n");
10634         MrBayesPrint ("                                                                                 \n");
10635         MrBayesPrint ("                       prset applyto=(3) statefreqs=dirichlet(1,1,1,1)           \n");
10636         MrBayesPrint ("                                                                                 \n");
10637         MrBayesPrint ("                    The first applies the parameters after \"applyto\"           \n");
10638         MrBayesPrint ("                    to the first and second partitions. The second prset         \n");
10639         MrBayesPrint ("                    applies a flat Dirichlet to the third partition. You can     \n");
10640         MrBayesPrint ("                    also use applyto=(all), which attempts to apply the para-    \n");
10641         MrBayesPrint ("                    meter settings to all of the data partitions. Importantly,   \n");
10642         MrBayesPrint ("                    if the option is not consistent with the data in the part-   \n");
10643         MrBayesPrint ("                    ition, the program will not apply the prset option to        \n");
10644         MrBayesPrint ("                    that partition.                                              \n");
10645         MrBayesPrint ("   Tratiopr      -- This parameter sets the prior for the transition/trans-      \n");
10646         MrBayesPrint ("                    version rate ratio (tratio). The options are:                \n");
10647         MrBayesPrint ("                                                                                 \n");
10648         MrBayesPrint ("                       prset tratiopr = beta(<number>, <number>)                 \n");
10649         MrBayesPrint ("                       prset tratiopr = fixed(<number>)                          \n");
10650         MrBayesPrint ("                                                                                 \n");
10651         MrBayesPrint ("                    The program assumes that the transition and transversion     \n");
10652         MrBayesPrint ("                    rates are independent gamma-distributed random variables     \n");
10653         MrBayesPrint ("                    with the same scale parameter when beta is selected. If you  \n");
10654         MrBayesPrint ("                    want a diffuse prior that puts equal emphasis on transition/ \n");
10655         MrBayesPrint ("                    transversion rate ratios above 1.0 and below 1.0, then use a \n");
10656         MrBayesPrint ("                    flat Beta, beta(1,1), which is the default. If you wish to   \n");
10657         MrBayesPrint ("                    concentrate this distribution more in the equal-rates region,\n");
10658         MrBayesPrint ("                    then use a prior of the type beta(x,x), where the magnitude  \n");
10659         MrBayesPrint ("                    of x determines how much the prior is concentrated in the    \n");
10660         MrBayesPrint ("                    equal rates region. For instance, a beta(20,20) puts more    \n");
10661         MrBayesPrint ("                    probability on rate ratios close to 1.0 than a beta(1,1). If \n");
10662         MrBayesPrint ("                    you think it is likely that the transition/transversion rate \n");
10663         MrBayesPrint ("                    ratio is 2.0, you can use a prior of the type beta(2x,x),    \n");
10664         MrBayesPrint ("                    where x determines how strongly the prior is concentrated on \n");
10665         MrBayesPrint ("                    tratio values near 2.0. For instance, a beta(2,1) is much    \n");
10666         MrBayesPrint ("                    more diffuse than a beta(80,40) but both have the expected   \n");
10667         MrBayesPrint ("                    tratio 2.0 in the absence of data. The parameters of the     \n");
10668         MrBayesPrint ("                    Beta can be interpreted as counts: if you have observed x    \n");
10669         MrBayesPrint ("                    transitions and y transversions, then a beta(x+1,y+1) is a   \n");
10670         MrBayesPrint ("                    good representation of this information. The fixed option    \n");
10671         MrBayesPrint ("                    allows you to fix the tratio to a particular value.          \n");
10672         MrBayesPrint ("   Revmatpr      -- This parameter sets the prior for the substitution rates     \n");
10673         MrBayesPrint ("                    of the GTR model for nucleotide data. The options are:       \n");
10674         MrBayesPrint ("                                                                                 \n");
10675         MrBayesPrint ("                       prset revmatpr = dirichlet(<number>,<number>,...,<number>)\n");
10676         MrBayesPrint ("                       prset revmatpr = fixed(<number>,<number>,...,<number>)    \n");
10677         MrBayesPrint ("                                                                                 \n");
10678         MrBayesPrint ("                    The program assumes that the six substitution rates          \n");
10679         MrBayesPrint ("                    are independent gamma-distributed random variables with the  \n");
10680         MrBayesPrint ("                    same scale parameter when dirichlet is selected. The six     \n");
10681         MrBayesPrint ("                    numbers in brackets each corresponds to a particular substi- \n");
10682         MrBayesPrint ("                    tution type. Together, they determine the shape of the prior.\n");
10683         MrBayesPrint ("                    The six rates are in the order A<->C, A<->G, A<->T, C<->G,   \n");
10684         MrBayesPrint ("                    C<->T, and G<->T. If you want an uninformative prior you can \n");
10685         MrBayesPrint ("                    use dirichlet(1,1,1,1,1,1), also referred to as a 'flat'     \n");
10686         MrBayesPrint ("                    Dirichlet. This is the default setting. If you wish a prior  \n");
10687         MrBayesPrint ("                    where the C<->T rate is 5 times and the A<->G rate 2 times   \n");
10688         MrBayesPrint ("                    higher, on average, than the transversion rates, which are   \n");
10689         MrBayesPrint ("                    all the same, then you should use a prior of the form        \n");
10690         MrBayesPrint ("                    dirichlet(x,2x,x,x,5x,x), where x determines how much the    \n");
10691         MrBayesPrint ("                    prior is focused on these particular rates. For more info,   \n");
10692         MrBayesPrint ("                    see tratiopr. The fixed option allows you to fix the substi- \n");
10693         MrBayesPrint ("                    tution rates to particular values.                           \n");
10694         MrBayesPrint ("   Revratepr     -- This parameter sets the prior for each substitution rate of  \n");
10695         MrBayesPrint ("                    the GTR model subspace when 'nst' is set to 'mixed' (see the \n");
10696         MrBayesPrint ("                    'lset' command). The only option is                          \n");
10697         MrBayesPrint ("                                                                                 \n");
10698         MrBayesPrint ("                       prset revratepr = symdir(<number>)                        \n");
10699         MrBayesPrint ("                                                                                 \n");
10700         MrBayesPrint ("                    which will associate each independent rate in the rate matrix\n");
10701         MrBayesPrint ("                    with a modified symmetric Dirichlet prior, where a singleton \n");
10702         MrBayesPrint ("                    rate has the specified alpha parameter, while a rate that    \n");
10703         MrBayesPrint ("                    applies to n pairwise substitution types has an alpha that is\n");
10704         MrBayesPrint ("                    n times the specified number. The higher the specified num-  \n");
10705         MrBayesPrint ("                    ber, the more focused the prior will be on equal rates. The  \n");
10706         MrBayesPrint ("                    default value is 1, which gives an effect similar to a flat  \n");
10707         MrBayesPrint ("                    Dirichlet.                                                   \n");
10708         MrBayesPrint ("   Aamodelpr     -- This parameter sets the rate matrix for amino acid data.     \n");
10709         MrBayesPrint ("                    You can either fix the model by specifying aamodelpr=fixed   \n");
10710         MrBayesPrint ("                    (<model name>), where <model name> is 'poisson' (a glorified \n");
10711         MrBayesPrint ("                    Jukes-Cantor model), 'jones', 'dayhoff', 'mtrev', 'mtmam',   \n");
10712         MrBayesPrint ("                    'wag', 'rtrev', 'cprev', 'vt', 'blosum', 'lg', 'equalin'     \n");
10713         MrBayesPrint ("                    (a glorified Felsenstein 1981 model), or 'gtr'. You can also \n");
10714         MrBayesPrint ("                    average over the first ten models by specifying aamodelpr=   \n");
10715         MrBayesPrint ("                    mixed. If you do so, the Markov chain will sample each model \n");
10716         MrBayesPrint ("                    according to its probability. The sampled model is reported  \n");
10717         MrBayesPrint ("                    as an index: poisson(0), jones(1), dayhoff(2), mtrev(3),     \n");
10718         MrBayesPrint ("                    mtmam(4), wag(5), rtrev(6), cprev(7), vt(8), or blosum(9).   \n");
10719         MrBayesPrint ("                    The 'Sump' command summarizes the MCMC samples and calculates\n");
10720         MrBayesPrint ("                    the posterior probability estimate for each of these models. \n");
10721         MrBayesPrint ("   Aarevmatpr    -- This parameter sets the prior for the substitution rates     \n");
10722         MrBayesPrint ("                    of the GTR model for amino acid data. The options are:       \n");
10723         MrBayesPrint ("                                                                                 \n");
10724         MrBayesPrint ("                       prset aarevmatpr = dirichlet(<number>,<number>,...,<number>)\n");
10725         MrBayesPrint ("                       prset aarevmatpr = fixed(<number>,<number>,...,<number>)  \n");
10726         MrBayesPrint ("                                                                                 \n");
10727         MrBayesPrint ("                    The options are the same as those for 'Revmatpr' except that \n");
10728         MrBayesPrint ("                    they are defined over the 190 rates of the time-reversible   \n");
10729         MrBayesPrint ("                    GTR model for amino acids instead of over the 6 rates of the \n");
10730         MrBayesPrint ("                    GTR model for nucleotides. The rates are in the order A<->R, \n");
10731         MrBayesPrint ("                    A<->N, etc to Y<->V. In other words, amino acids are listed  \n");
10732         MrBayesPrint ("                    in alphabetic order based on their full name. The first amino\n");
10733         MrBayesPrint ("                    acid (Alanine) is then combined in turn with all amino acids \n");
10734         MrBayesPrint ("                    following it in the list, starting with amino acid 2 (Argi-  \n");
10735         MrBayesPrint ("                    nine) and finishing with amino acid 20 (Valine). The second  \n");
10736         MrBayesPrint ("                    amino acid (Arginine) is then combined in turn with all amino\n");
10737         MrBayesPrint ("                    acids following it, starting with amino acid 3 (Asparagine)  \n");
10738         MrBayesPrint ("                    and finishing with amino acid 20 (Valine), and so on.        \n");
10739         MrBayesPrint ("   Omegapr       -- This parameter specifies the prior on the nonsynonymous/     \n");
10740         MrBayesPrint ("                    synonymous rate ratio. The options are:                      \n");
10741         MrBayesPrint ("                                                                                 \n");
10742         MrBayesPrint ("                       prset omegapr = dirichlet(<number>,<number>)              \n");
10743         MrBayesPrint ("                       prset omegapr = fixed(<number>)                           \n");
10744         MrBayesPrint ("                                                                                 \n");
10745         MrBayesPrint ("                    This parameter is only in effect if the nucleotide sub-      \n");
10746         MrBayesPrint ("                    stitution model is set to codon using the lset command       \n");
10747         MrBayesPrint ("                    (lset nucmodel=codon). Moreover, it only applies to the      \n");
10748         MrBayesPrint ("                    case when there is no variation in omega across sites (i.e., \n");
10749         MrBayesPrint ("                    \"lset omegavar=equal\").                                    \n");
10750         MrBayesPrint ("   Ny98omega1pr  -- This parameter specifies the prior on the nonsynonymous/     \n");
10751         MrBayesPrint ("                    synonymous rate ratio for sites under purifying selection.   \n");
10752         MrBayesPrint ("                    The options are:                                             \n");
10753         MrBayesPrint ("                                                                                 \n");
10754         MrBayesPrint ("                       prset Ny98omega1pr = beta(<number>,<number>)              \n");
10755         MrBayesPrint ("                       prset Ny98omega1pr = fixed(<number>)                      \n");
10756         MrBayesPrint ("                                                                                 \n");
10757         MrBayesPrint ("                    This parameter is only in effect if the nucleotide sub-      \n");
10758         MrBayesPrint ("                    stitution model is set to codon using the lset command       \n");
10759         MrBayesPrint ("                    (lset nucmodel=codon). Moreover, it only applies to the      \n");
10760         MrBayesPrint ("                    case where omega varies across sites using the model of      \n");
10761         MrBayesPrint ("                    Nielsen and Yang (1998) (i.e., \"lset omegavar=ny98\"). If   \n");
10762         MrBayesPrint ("                    fixing the parameter, you must specify a number between      \n");
10763         MrBayesPrint ("                    0 and 1.                                                     \n");
10764         MrBayesPrint ("   Ny98omega3pr  -- This parameter specifies the prior on the nonsynonymous/     \n");
10765         MrBayesPrint ("                    synonymous rate ratio for positively selected sites. The     \n");
10766         MrBayesPrint ("                    options are:                                                 \n");
10767         MrBayesPrint ("                                                                                 \n");
10768         MrBayesPrint ("                       prset Ny98omega3pr = uniform(<number>,<number>)           \n");
10769         MrBayesPrint ("                       prset Ny98omega3pr = exponential(<number>)                \n");
10770         MrBayesPrint ("                       prset Ny98omega3pr = fixed(<number>)                      \n");
10771         MrBayesPrint ("                                                                                 \n");
10772         MrBayesPrint ("                    This parameter is only in effect if the nucleotide sub-      \n");
10773         MrBayesPrint ("                    stitution model is set to codon using the lset command       \n");
10774         MrBayesPrint ("                    (lset nucmodel=codon). Moreover, it only applies to the      \n");
10775         MrBayesPrint ("                    case where omega varies across sites according to the        \n");
10776         MrBayesPrint ("                    NY98 model. Note that if the NY98 model is specified         \n");
10777         MrBayesPrint ("                    that this parameter must be greater than 1, so you should    \n");
10778         MrBayesPrint ("                    not specify a uniform(0,10) prior, for example.              \n");
10779         MrBayesPrint ("   M3omegapr     -- This parameter specifies the prior on the nonsynonymous/     \n");
10780         MrBayesPrint ("                    synonymous rate ratios for all three classes of sites for    \n");
10781         MrBayesPrint ("                    the M3 model. The options are:                               \n");
10782         MrBayesPrint ("                                                                                 \n");
10783         MrBayesPrint ("                       prset M3omegapr = exponential                             \n");
10784         MrBayesPrint ("                       prset M3omegapr = fixed(<number>,<number>,<number>)       \n");
10785         MrBayesPrint ("                                                                                 \n");
10786         MrBayesPrint ("                    This parameter is only in effect if the nucleotide sub-      \n");
10787         MrBayesPrint ("                    stitution model is set to codon using the lset command       \n");
10788         MrBayesPrint ("                    (lset nucmodel=codon). Moreover, it only applies to the      \n");
10789         MrBayesPrint ("                    case where omega varies across sites using the M3 model of   \n");
10790         MrBayesPrint ("                    Yang et al. (2000) (i.e., \"lset omegavar=M3\"). Under the   \n");
10791         MrBayesPrint ("                    exponential prior, the four rates (dN1, dN2, dN3, and dS)    \n");
10792         MrBayesPrint ("                    are all considered to be independent draws from the same     \n");
10793         MrBayesPrint ("                    exponential distribution (the parameter of the exponential   \n");
10794         MrBayesPrint ("                    does not matter, and so you don't need to specify it). The   \n");
10795         MrBayesPrint ("                    rates dN1, dN2, and dN3 are taken to be the order statistics \n");
10796         MrBayesPrint ("                    with dN1 < dN2 < dN3. These three rates are all scaled to    \n");
10797         MrBayesPrint ("                    the same synonymous rate, dS. The other option is to simply  \n");
10798         MrBayesPrint ("                    fix the three rate ratios to some values.                    \n");
10799         MrBayesPrint ("   Codoncatfreqs -- This parameter specifies the prior on frequencies of sites   \n");
10800         MrBayesPrint ("                    under purifying, neutral, and positive selection. The        \n");
10801         MrBayesPrint ("                    options are:                                                 \n");
10802         MrBayesPrint ("                                                                                 \n");
10803         MrBayesPrint ("                       prset codoncatfreqs = dirichlet(<num>,<num>,<num>)        \n");
10804         MrBayesPrint ("                       prset codoncatfreqs = fixed(<number>,<number>,<number>)   \n");
10805         MrBayesPrint ("                                                                                 \n");
10806         MrBayesPrint ("                    This parameter is only in effect if the nucleotide sub-      \n");
10807         MrBayesPrint ("                    stitution model is set to codon using the lset command       \n");
10808         MrBayesPrint ("                    (lset nucmodel=codon). Moreover, it only applies to the      \n");
10809         MrBayesPrint ("                    case where omega varies across sites using the models of     \n");
10810         MrBayesPrint ("                    Nielsen and Yang (1998) (i.e., \"lset omegavar=ny98\")       \n");
10811         MrBayesPrint ("                    or Yang et al. (2000) (i.e., \"lset omegavar=M3\")           \n");
10812         MrBayesPrint ("                    Note that the sum of the three frequencies must be 1.        \n");
10813         MrBayesPrint ("   Statefreqpr   -- This parameter specifies the prior on the state freq-        \n");
10814         MrBayesPrint ("                    uencies. The options are:                                    \n");
10815         MrBayesPrint ("                                                                                 \n");
10816         MrBayesPrint ("                       prset statefreqpr = dirichlet(<number>)                   \n");
10817         MrBayesPrint ("                       prset statefreqpr = dirichlet(<number>,...,<number>)      \n");
10818         MrBayesPrint ("                       prset statefreqpr = fixed(equal)                          \n");
10819         MrBayesPrint ("                       prset statefreqpr = fixed(empirical)                      \n");
10820         MrBayesPrint ("                       prset statefreqpr = fixed(<number>,...,<number>)          \n");
10821         MrBayesPrint ("                                                                                 \n");
10822         MrBayesPrint ("                    For the dirichlet, you can specify either a single number    \n");
10823         MrBayesPrint ("                    or as many numbers as there are states. If you specify a     \n");
10824         MrBayesPrint ("                    single number, then the prior has all states equally         \n");
10825         MrBayesPrint ("                    probable with a variance related to the single parameter     \n");
10826         MrBayesPrint ("                    passed in.                                                   \n");
10827         MrBayesPrint ("   Shapepr       -- This parameter specifies the prior for the gamma/lnorm shape \n");
10828         MrBayesPrint ("                    parameter for among-site rate variation. The options are:    \n");
10829         MrBayesPrint ("                                                                                 \n");
10830         MrBayesPrint ("                       prset shapepr = uniform(<number>,<number>)                \n");
10831         MrBayesPrint ("                       prset shapepr = exponential(<number>)                     \n");
10832         MrBayesPrint ("                       prset shapepr = fixed(<number>)                           \n");
10833         MrBayesPrint ("                                                                                 \n");
10834         MrBayesPrint ("   Pinvarpr      -- This parameter specifies the prior for the proportion of     \n");
10835         MrBayesPrint ("                    invariable sites. The options are:                           \n");
10836         MrBayesPrint ("                                                                                 \n");
10837         MrBayesPrint ("                       prset pinvarpr = uniform(<number>,<number>)               \n");
10838         MrBayesPrint ("                       prset pinvarpr = fixed(<number>)                          \n");
10839         MrBayesPrint ("                                                                                 \n");
10840         MrBayesPrint ("                    Note that the valid range for the parameter is between 0     \n");
10841         MrBayesPrint ("                    and 1. Hence, \"prset pinvarpr=uniform(0,0.8)\" is valid     \n");
10842         MrBayesPrint ("                    while \"prset pinvarpr=uniform(0,10)\" is not. The def-      \n");
10843         MrBayesPrint ("                    ault setting is \"prset pinvarpr=uniform(0,1)\".             \n");
10844         MrBayesPrint ("   Ratecorrpr    -- This parameter specifies the prior for the autocorrelation   \n");
10845         MrBayesPrint ("                    parameter of the autocorrelated gamma distribution for       \n");
10846         MrBayesPrint ("                    among-site rate variation. The options are:                  \n");
10847         MrBayesPrint ("                                                                                 \n");
10848         MrBayesPrint ("                       prset ratecorrpr = uniform(<number>,<number>)             \n");
10849         MrBayesPrint ("                       prset ratecorrpr = fixed(<number>)                        \n");
10850         MrBayesPrint ("                                                                                 \n");
10851         MrBayesPrint ("                    Note that the valid range for the parameter is between -1    \n");
10852         MrBayesPrint ("                    and 1. Hence, \"prset ratecorrpr=uniform(-1,1)\" is valid    \n");
10853         MrBayesPrint ("                    while \"prset ratecorrpr=uniform(-11,10)\" is not. The       \n");
10854         MrBayesPrint ("                    default setting is \"prset ratecorrpr=uniform(-1,1)\".       \n");
10855         MrBayesPrint ("   Covswitchpr   -- This option sets the prior for the covarion switching        \n");
10856         MrBayesPrint ("                    rates. The options are:                                      \n");
10857         MrBayesPrint ("                                                                                 \n");
10858         MrBayesPrint ("                       prset covswitchpr = uniform(<number>,<number>)            \n");
10859         MrBayesPrint ("                       prset covswitchpr = exponential(<number>)                 \n");
10860         MrBayesPrint ("                       prset covswitchpr = fixed(<number>,<number>)              \n");
10861         MrBayesPrint ("                                                                                 \n");
10862         MrBayesPrint ("                    The covarion model has two rates: a rate from on to off      \n");
10863         MrBayesPrint ("                    and a rate from off to on. The rates are assumed to have     \n");
10864         MrBayesPrint ("                    independent priors that individually are either uniformly    \n");
10865         MrBayesPrint ("                    or exponentially distributed. The other option is to         \n");
10866         MrBayesPrint ("                    fix the switching rates, in which case you must specify      \n");
10867         MrBayesPrint ("                    both rates. (The first number is off->on and the second      \n");
10868         MrBayesPrint ("                    is on->off).                                                 \n");
10869         MrBayesPrint ("   Symdirihyperpr - This option sets the prior for the stationary frequencies    \n");
10870         MrBayesPrint ("                    of the states for morphological (standard) data. There can   \n");
10871         MrBayesPrint ("                    be as many as 10 states for standard data. However, the      \n");
10872         MrBayesPrint ("                    labelling of the states is somewhat arbitrary. For example,  \n");
10873         MrBayesPrint ("                    the state \"1\" for different characters does not have the   \n");
10874         MrBayesPrint ("                    same meaning. This is not true for DNA characters, for ex-   \n");
10875         MrBayesPrint ("                    ample, where a \"G\" has the same meaning across characters. \n");
10876         MrBayesPrint ("                    The fact that the labelling of morphological characters is   \n");
10877         MrBayesPrint ("                    arbitrary makes it difficult to allow unequal character-     \n");
10878         MrBayesPrint ("                    state frequencies. MrBayes gets around this problem by       \n");
10879         MrBayesPrint ("                    assuming that the states have a symmetric Dirichlet prior    \n");
10880         MrBayesPrint ("                    (i.e. all Dirichlet parameters are equal). The variation in  \n");
10881         MrBayesPrint ("                    the Dirichlet can be controlled by this parameter.           \n");
10882         MrBayesPrint ("                    Symdirihyperpr specifies the distribution on the parameter   \n");
10883         MrBayesPrint ("                    of the symmetric Dirichlet. The valid options are:           \n");
10884         MrBayesPrint ("                                                                                 \n");
10885         MrBayesPrint ("                       prset Symdirihyperpr = uniform(<number>,<number>)         \n");
10886         MrBayesPrint ("                       prset Symdirihyperpr = exponential(<number>)              \n");
10887         MrBayesPrint ("                       prset Symdirihyperpr = fixed(<number>)                    \n");
10888         MrBayesPrint ("                       prset Symdirihyperpr = fixed(infinity)                    \n");
10889         MrBayesPrint ("                                                                                 \n");
10890         MrBayesPrint ("                    If \"fixed(infinity)\" is chosen, the Dirichlet prior is     \n");
10891         MrBayesPrint ("                    fixed such that all character states have equal frequency.   \n");
10892         MrBayesPrint ("   Topologypr    -- This parameter specifies the prior probabilities of          \n");
10893         MrBayesPrint ("                    phylogenies. The options are:                                \n");
10894         MrBayesPrint ("                                                                                 \n");
10895         MrBayesPrint ("                       prset topologypr = uniform                                \n");
10896         MrBayesPrint ("                       prset topologypr = speciestree                            \n");
10897         MrBayesPrint ("                       prset topologypr = constraints(<list>)                    \n");
10898         MrBayesPrint ("                       prset topologypr = fixed(<treename>)                      \n");
10899         MrBayesPrint ("                                                                                 \n");
10900         MrBayesPrint ("                    If the prior is selected to be \"uniform\", the default,     \n");
10901         MrBayesPrint ("                    then all possible trees are considered a priori equally      \n");
10902         MrBayesPrint ("                    probable. The 'speciestree' option is used when the topology \n");
10903         MrBayesPrint ("                    is constrained to fold inside a species tree together with   \n");
10904         MrBayesPrint ("                    other (gene) trees. The constraints option allows you to     \n");
10905         MrBayesPrint ("                    specify complicated prior probabilities on trees (constraints\n");
10906         MrBayesPrint ("                    are discussed more fully in \"help constraint\"). Note that  \n");
10907         MrBayesPrint ("                    you must specify a list of constraints that you wish to be   \n");
10908         MrBayesPrint ("                    obeyed. The list can be either the constraints' name or      \n");
10909         MrBayesPrint ("                    number. Finally, you can fix the topology to that of a user  \n");
10910         MrBayesPrint ("                    tree defined in a trees block. Branch lengths will still be  \n");
10911         MrBayesPrint ("                    sampled as usual on the fixed topology.                      \n");
10912         MrBayesPrint ("   Brlenspr      -- This parameter specifies the prior probability dist-         \n");
10913         MrBayesPrint ("                    ribution on branch lengths. The options are specified using: \n");
10914         MrBayesPrint ("                                                                                 \n");
10915         MrBayesPrint ("                       prset brlenspr = <setting>                                \n");
10916         MrBayesPrint ("                                                                                 \n");
10917         MrBayesPrint ("                    where <setting> is one of                                    \n");
10918         MrBayesPrint ("                                                                                 \n");
10919         MrBayesPrint ("                       unconstrained:uniform(<num>,<num>)                        \n");
10920         MrBayesPrint ("                       unconstrained:exponential(<number>)                       \n");
10921         MrBayesPrint ("                       unconstrained:twoexp(<num>,<num>)                         \n");
10922         MrBayesPrint ("                       unconstrained:gammadir(<num>,<num>,<num>,<num>)           \n");
10923         MrBayesPrint ("                       unconstrained:invgamdir(<num>,<num>,<num>,<num>)          \n");
10924         MrBayesPrint ("                       clock:uniform                                             \n");
10925         MrBayesPrint ("                       clock:birthdeath                                          \n");
10926         MrBayesPrint ("                       clock:coalescence                                         \n");
10927         MrBayesPrint ("                       clock:fossilization                                       \n");
10928         MrBayesPrint ("                       clock:speciestree                                         \n");
10929         MrBayesPrint ("                       fixed(<treename>)                                         \n");
10930         MrBayesPrint ("                                                                                 \n");
10931         MrBayesPrint ("                    Trees with unconstrained branch lengths are unrooted         \n");
10932         MrBayesPrint ("                    whereas clock-constrained trees are rooted. The option       \n");
10933         MrBayesPrint ("                    after the colon specifies the details of the probability     \n");
10934         MrBayesPrint ("                    density of branch lengths. If you choose a birth-death       \n");
10935         MrBayesPrint ("                    or coalescence prior, you may want to modify the details     \n");
10936         MrBayesPrint ("                    of the parameters of those processes (speciation rate,       \n");
10937         MrBayesPrint ("                    extinction rate and sample probability for the birth-death   \n");
10938         MrBayesPrint ("                    prior; population size and clock rate parameter for the      \n");
10939         MrBayesPrint ("                    coalescence prior). When gene trees are constrained to fold  \n");
10940         MrBayesPrint ("                    inside species trees, the appropriate branch length prior is \n");
10941         MrBayesPrint ("                    'clock:speciestree'. Under this model, it is possible to     \n");
10942         MrBayesPrint ("                    control whether the population size is constant or variable  \n");
10943         MrBayesPrint ("                    across the species tree using the 'popvarpr' setting.        \n");
10944         MrBayesPrint ("                    Branch lengths can also be fixed but only if the topology is \n");
10945         MrBayesPrint ("                    fixed.                                                       \n");
10946         MrBayesPrint ("                                                                                 \n");
10947         MrBayesPrint ("                    For unconstrained branch lengths, MrBayes offers five alter- \n");
10948         MrBayesPrint ("                    native prior distributions. The first two are the simple     \n");
10949         MrBayesPrint ("                    'uniform' and 'exponential' priors. The 'uniform' prior takes\n");
10950         MrBayesPrint ("                    two parameters, the lower and upper bound of the uniform dis-\n");
10951         MrBayesPrint ("                    tribution, respectively. The 'exponential' prior takes a sin-\n");
10952         MrBayesPrint ("                    gle parameter, the rate of the exponential distribution. The \n");
10953         MrBayesPrint ("                    mean of the exponential distribution is the inverse of the   \n");
10954         MrBayesPrint ("                    rate. For instance, an 'exp(10)' distribution has an expected\n");
10955         MrBayesPrint ("                    mean of 0.1.                                                 \n");
10956         MrBayesPrint ("                    MrBayes also offers three more complex prior distributions   \n");
10957         MrBayesPrint ("                    on unconstrained branch lengths. The two-exponential prior   \n");
10958         MrBayesPrint ("                    (Yang and Rannala 2005; Yang 2007) uses two different expo-  \n");
10959         MrBayesPrint ("                    nential distributions, one for internal and one for external \n");
10960         MrBayesPrint ("                    branch lengths. The two-exponential prior is invoked using   \n");
10961         MrBayesPrint ("                    'twoexp(<r_I>,<r_E>)', where '<r_I>' is a number specifying  \n");
10962         MrBayesPrint ("                    the rate of the exponential distribution on internal branch  \n");
10963         MrBayesPrint ("                    lengths, while '<r_E>' is the rate for external branch       \n");
10964         MrBayesPrint ("                    lengths. The prior mean for internal branch lengths is then  \n");
10965         MrBayesPrint ("                    1/r_I, and for external ones is 1/r_E. For instance, to set  \n");
10966         MrBayesPrint ("                    prior mean of internal branch lengths to 0.01, and external  \n");
10967         MrBayesPrint ("                    ones to 0.1, use 'twoexp(100,10)'.                           \n");
10968         MrBayesPrint ("                    The setting 'twoexp(10,10)' is equivalent to 'exp(10)'.      \n");
10969         MrBayesPrint ("                    The compound Dirichlet priors 'gammadir(<a_T>,<b_T>,<a>,<c>)'\n");
10970         MrBayesPrint ("                    and 'invgamdir(<a_T>,<b_T>,<a>,<c>)' specify a fairly diffuse\n");
10971         MrBayesPrint ("                    prior on tree length 'T', and then partition the tree length \n");
10972         MrBayesPrint ("                    into branch lengths according to a Dirichlet distribution    \n");
10973         MrBayesPrint ("                    (Rannala et al. 2012). If 'T' is considered drawn from a     \n");
10974         MrBayesPrint ("                    gamma distribution with parameters a_T and b_T, and with mean\n");
10975         MrBayesPrint ("                    a_T/b_T, we recommend setting a_T = 1; if it is instead con- \n");
10976         MrBayesPrint ("                    sidered drawn from an inverse gamma (invgamma) distribution  \n");
10977         MrBayesPrint ("                    with parameters a_T and b_T, and with mean b_T/(a_T -1), then\n");
10978         MrBayesPrint ("                    we recommend setting a_T = 3. In the latter case, b_T should \n");
10979         MrBayesPrint ("                    be chosen so that the prior mean of T is reasonable for the  \n");
10980         MrBayesPrint ("                    data. In the former case, setting b_T = 0.1 (corresponding to\n");
10981         MrBayesPrint ("                    a mean tree length of 10) should be appropriate for a wide   \n");
10982         MrBayesPrint ("                    range of tree lengths (at least in the interval 1 to 100).   \n");
10983         MrBayesPrint ("                    The concentration parameter a of the Dirichlet distribution  \n");
10984         MrBayesPrint ("                    is inversely related to the variance of the branch lengths,  \n");
10985         MrBayesPrint ("                    while c is the ratio of the prior means for the internal and \n");
10986         MrBayesPrint ("                    external branch lengths. The default setting, a = c = 1,     \n");
10987         MrBayesPrint ("                    specifies a uniform Dirichlet distribution of branch lengths \n");
10988         MrBayesPrint ("                    given the tree length. For instance, 'gammadir(1,0.1,1,1)'   \n");
10989         MrBayesPrint ("                    specifies a compound Dirichlet prior on branch lengths, where\n");
10990         MrBayesPrint ("                    tree length is associated with a gamma distribution with mean\n");
10991         MrBayesPrint ("                    10, and branch length proportions are associated with a uni- \n");
10992         MrBayesPrint ("                    form Dirichlet distribution (default).                       \n");
10993         MrBayesPrint ("                                                                                 \n");
10994         MrBayesPrint ("                    For clock trees with calibrated external nodes (fossils),    \n");
10995         MrBayesPrint ("                    MrBayes also offers the fossilized birth-death prior:        \n");
10996         MrBayesPrint ("                    'clock:fossilization'.                                       \n");
10997         MrBayesPrint ("                    If 'SampleStrat' is set to 'fossiltip', it assumes that upon \n");
10998         MrBayesPrint ("                    sampling the lineage is dead and won't produce descendants,  \n");
10999         MrBayesPrint ("                    meaning each fossil sample is a tip. If 'SampleStrat' is set \n");
11000         MrBayesPrint ("                    to 'random' (default), fossils are sampled serially along the\n");
11001         MrBayesPrint ("                    birth-death tree (Stadler 2010), so they can be tips or an-  \n");
11002         MrBayesPrint ("                    cestors. See 'Speciationpr', 'Extinctionpr', 'SampleStrat',  \n");
11003         MrBayesPrint ("                    'Fossilizationpr' for more information.                      \n");
11004         MrBayesPrint ("                                                                                 \n");
11005         MrBayesPrint ("   Treeagepr     -- This parameter specifies the prior probability distribution  \n");
11006         MrBayesPrint ("                    on the tree age when a uniform or fossilization prior is used\n");
11007         MrBayesPrint ("                    on the branch lengths of a clock tree.                       \n");
11008         MrBayesPrint ("                                                                                 \n");
11009         MrBayesPrint ("                    The options are:                                             \n");
11010         MrBayesPrint ("                                                                                 \n");
11011         MrBayesPrint ("                       prset treeagepr = <setting>                               \n");
11012         MrBayesPrint ("                                                                                 \n");
11013         MrBayesPrint ("                    where <setting> is one of                                    \n");
11014         MrBayesPrint ("                                                                                 \n");
11015         MrBayesPrint ("                       fixed(<age>)                                              \n");
11016         MrBayesPrint ("                       uniform(<min_age>,<max_age>)                              \n");
11017         MrBayesPrint ("                       offsetexponential(<min_age>,<mean_age>)                   \n");
11018         MrBayesPrint ("                       truncatednormal(<min_age>,<mean_age>,<st.dev.>)           \n");
11019         MrBayesPrint ("                       lognormal(<mean_age>,<st.dev.>)                           \n");
11020         MrBayesPrint ("                       offsetlognormal(<min_age>,<mean_age>,<st.dev.>)           \n");
11021         MrBayesPrint ("                       gamma(<mean_age>,<st.dev.>)                               \n");
11022         MrBayesPrint ("                       offsetgamma(<min_age>,<mean_age>,<st.dev.>)               \n");
11023         MrBayesPrint ("                                                                                 \n");
11024         MrBayesPrint ("                    These are the same options used for the 'Calibrate' command. \n");
11025         MrBayesPrint ("                    Note that, unlike elsewhere in MrMayes, we always use the    \n");
11026         MrBayesPrint ("                    mean and standard deviation of the resulting age distribution\n");
11027         MrBayesPrint ("                    rather than the standard parameterization, if different. This\n");
11028         MrBayesPrint ("                    is to facilitate for the users who want to focus on the in-  \n");
11029         MrBayesPrint ("                    formation conveyed about the age. For those who wish to use  \n");
11030         MrBayesPrint ("                    the standard parameterization, there are simple conversions  \n");
11031         MrBayesPrint ("                    between the two. See the 'Calibrate' command for more infor- \n");
11032         MrBayesPrint ("                    mation.                                                      \n");
11033         MrBayesPrint ("                                                                                 \n");
11034         MrBayesPrint ("                    The tree age is simply the age of the most recent common     \n");
11035         MrBayesPrint ("                    ancestor of the tree. If the clock rate is fixed to 1.0,     \n");
11036         MrBayesPrint ("                    which is the default, the tree age is equivalent to the      \n");
11037         MrBayesPrint ("                    expected number of substitutions from the root to the tip of \n");
11038         MrBayesPrint ("                    the tree, that is, tree height. The tree age prior ensures   \n");
11039         MrBayesPrint ("                    that the joint probability for the uniform prior (or fossil- \n");
11040         MrBayesPrint ("                    ization prior) model of branch lengths on a clock tree is    \n");
11041         MrBayesPrint ("                    proper. The default setting is 'gamma(1,1)'. If the root node\n");
11042         MrBayesPrint ("                    in the tree is calibrated, the root calibration replaces the \n");
11043         MrBayesPrint ("                    tree age prior.                                              \n");
11044         MrBayesPrint ("   Speciationpr  -- This parameter sets the prior on the net speciation rate (net\n");
11045         MrBayesPrint ("                    diversification), that is, (lambda - mu) in the birth-death  \n");
11046         MrBayesPrint ("                    model and the general case of fossilized birth-death model.  \n");
11047         MrBayesPrint ("                    Or, (lambda - mu - psi) in the special case of f-b-d model   \n");
11048         MrBayesPrint ("                    (fossiltip). Values of this parameter are > 0. Prior options:\n");
11049         MrBayesPrint ("                                                                                 \n");
11050         MrBayesPrint ("                       prset speciationpr = uniform(<number>,<number>)           \n");
11051         MrBayesPrint ("                       prset speciationpr = exponential(<number>)                \n");
11052         MrBayesPrint ("                       prset speciationpr = fixed(<number>)                      \n");
11053         MrBayesPrint ("                                                                                 \n");
11054         MrBayesPrint ("                    This parameter is only relevant if the (fossil) birth-death  \n");
11055         MrBayesPrint ("                    process is selected as the prior on branch lengths.          \n");
11056         MrBayesPrint ("   Extinctionpr  -- This parameter sets the prior on the relative extinction rate\n");
11057         MrBayesPrint ("                    (turnover), that is, (mu / lambda) in the birth-death model  \n");
11058         MrBayesPrint ("                    and the general case of fossilized birth-death model.        \n");
11059         MrBayesPrint ("                    Or, (mu + psi) / lambda in the special case of f-b-d model   \n");
11060         MrBayesPrint ("                    (fossiltip). Values of this parameter are in range (0,1).    \n");
11061         MrBayesPrint ("                                                                                 \n");
11062         MrBayesPrint ("                       prset extinctionpr = beta(<number>,<number>)              \n");
11063         MrBayesPrint ("                       prset extinctionpr = fixed(<number>)                      \n");
11064         MrBayesPrint ("                                                                                 \n");
11065         MrBayesPrint ("                    This parameter is only relevant if the (fossil) birth-death  \n");
11066         MrBayesPrint ("                    process is selected as the prior on branch lengths.          \n");
11067         MrBayesPrint (" Fossilizationpr -- This parameter sets the prior on the relative fossilization  \n");
11068         MrBayesPrint ("                    rate (sampling proportion), psi/(mu+psi), in the fossilized  \n");
11069         MrBayesPrint ("                    b-d model. Values of this parameter are in range (0,1).      \n");
11070         MrBayesPrint ("                    If SampleStrat is used to divide up time intervals, it sets  \n");
11071         MrBayesPrint ("                    the prior for the fossilization parameter in each interval.  \n");
11072         MrBayesPrint ("                                                                                 \n");
11073         MrBayesPrint ("                       prset fossilizationpr = beta(<number>,<number>)           \n");
11074         MrBayesPrint ("                       prset fossilizationpr = fixed(<number>)                   \n");
11075         MrBayesPrint ("                                                                                 \n");
11076         MrBayesPrint ("                    This parameter is only relevant if the fossilized birth-death\n");
11077         MrBayesPrint ("                    process is selected as the prior on branch lengths.          \n");
11078         MrBayesPrint ("   SampleStrat   -- This parameter sets the strategy under which species were    \n");
11079         MrBayesPrint ("                    sampled in the analysis. For the birth-death prior, 'birth-  \n");
11080         MrBayesPrint ("                    death' (Hohna et al. 2011), three strategies: 'random',      \n");
11081         MrBayesPrint ("                    'diversity' and 'cluster' sampling can be used for extant    \n");
11082         MrBayesPrint ("                    taxa. No extinct sample (fossil) is allowed in this prior.   \n");
11083         MrBayesPrint ("                    For data with extant and extinct samples, use 'prset brlenspr\n");
11084         MrBayesPrint ("                    =clock:fossilization'. (Stadler 2010; Zhang et al. 2015)     \n");
11085         MrBayesPrint ("                    For the fossilized birth-death prior, 'fossiltip' assumes    \n");
11086         MrBayesPrint ("                    extant taxa are sampled randomly, and extinct taxa (fossils) \n");
11087         MrBayesPrint ("                    are sampled with constant rate and upon sampling the lineage \n");
11088         MrBayesPrint ("                    is dead and won't produce any descendant, so fossils are all \n");
11089         MrBayesPrint ("                    at tips. Except 'fossiltip', the following strategies allow  \n");
11090         MrBayesPrint ("                    fossils also being ancestors of other samples.               \n");
11091         MrBayesPrint ("                    'random' (default) assumes extant taxa are sampled uniformly \n");
11092         MrBayesPrint ("                    at random with prob rho, 'diversity' assumes extant taxa are \n");
11093         MrBayesPrint ("                    sampled to maximize diversity with prop (set in sampleprob). \n");
11094         MrBayesPrint ("                    Fossils are sampled on the birth-death tree with piecewise   \n");
11095         MrBayesPrint ("                    constant rates, psi_i (i = 1,...,s+1). Time is divided by <s>\n");
11096         MrBayesPrint ("                    slices in the past, each at time <t_i> (s >= 0).             \n");
11097         MrBayesPrint ("                                                                                 \n");
11098         MrBayesPrint ("                       prset samplestrat = random                                \n");
11099         MrBayesPrint ("                       prset samplestrat = diversity                             \n");
11100         MrBayesPrint ("                       prset samplestrat = cluster                               \n");
11101         MrBayesPrint ("                       prset samplestrat = fossiltip                             \n");
11102         MrBayesPrint ("                       prset samplestrat = random    <s>: ... <t_i> ...          \n");
11103         MrBayesPrint ("                       prset samplestrat = diversity <s>: ... <t_i> ...          \n");
11104         MrBayesPrint ("                                                                                 \n");
11105         MrBayesPrint ("   Sampleprob    -- This parameter sets the fraction of extant species that are  \n");
11106         MrBayesPrint ("                    sampled in the analysis. This is used with the birth-death   \n");
11107         MrBayesPrint ("                    prior on trees (Yang and Rannala 1997; Stadler 2009; Hohna   \n");
11108         MrBayesPrint ("                    et al. 2011), and the fossilized birth-death prior (Stadler  \n");
11109         MrBayesPrint ("                    2010, Zhang et al. 2015).                                    \n");
11110         MrBayesPrint ("                                                                                 \n");
11111         MrBayesPrint ("                       prset sampleprob = <number>                               \n");
11112         MrBayesPrint ("                                                                                 \n");
11113         MrBayesPrint ("   Popsizepr     -- This parameter sets the prior on the population size compo-  \n");
11114         MrBayesPrint ("                    nent of the coalescent parameter. The options are:           \n");
11115         MrBayesPrint ("                                                                                 \n");
11116         MrBayesPrint ("                       prset popsizepr = uniform(<number>,<number>)              \n");
11117         MrBayesPrint ("                       prset popsizepr = lognormal(<number>,<number>)            \n");
11118         MrBayesPrint ("                       prset popsizepr = normal(<number>,<number>)               \n");
11119         MrBayesPrint ("                       prset popsizepr = gamma(<number>,<number>)                \n");
11120         MrBayesPrint ("                       prset popsizepr = fixed(<number>)                         \n");
11121         MrBayesPrint ("                                                                                 \n");
11122         MrBayesPrint ("                    This parameter is only relevant if the coalescence process is\n");
11123         MrBayesPrint ("                    selected as the prior on branch lengths. Note that the set-  \n");
11124         MrBayesPrint ("                    ting of 'ploidy' in 'lset' is important for how this para-   \n");
11125         MrBayesPrint ("                    meter is interpreted.                                        \n");
11126         MrBayesPrint ("   Popvarpr      -- In a gene tree - species tree model, this parameter deter-   \n");
11127         MrBayesPrint ("                    mines whether the population size is the same for the entire \n");
11128         MrBayesPrint ("                    species tree ('popvarpr = equal', the default), or varies    \n");
11129         MrBayesPrint ("                    across branches of the species tree ('popvarpr=variable').   \n");
11130 /*      MrBayesPrint ("   Growthpr      -- This parameter sets the prior on the exponential growth      \n");
11131         MrBayesPrint ("                    parameter of the coalescence process. The options are:       \n");
11132         MrBayesPrint ("                                                                                 \n");
11133         MrBayesPrint ("                       prset growthpr = uniform(<number>,<number>)               \n");
11134         MrBayesPrint ("                       prset growthpr = exponential(<number>)                    \n");
11135         MrBayesPrint ("                       prset growthpr = fixed(<number>)                          \n");
11136         MrBayesPrint ("                                                                                 \n");
11137         MrBayesPrint ("                    This parameter is only relevant if the coalescence           \n");
11138         MrBayesPrint ("                    process is selected as the prior on branch lengths.          \n"); */
11139         MrBayesPrint ("   Nodeagepr     -- This parameter specifies the assumptions concerning the age  \n");
11140         MrBayesPrint ("                    of the terminal and interior nodes in the tree. The default  \n");
11141         MrBayesPrint ("                    model ('nodeagepr = unconstrained') assumes that all terminal\n");
11142         MrBayesPrint ("                    nodes are of the same age while the age of interior nodes is \n");
11143         MrBayesPrint ("                    unconstrained. The alternative ('nodeagepr = calibrated')    \n");
11144         MrBayesPrint ("                    option derives a prior probability distribution on terminal  \n");
11145         MrBayesPrint ("                    and interior node ages from the calibration settings (see    \n");
11146         MrBayesPrint ("                    the 'calibrate' command). The 'nodeagepr' parameter is only  \n");
11147         MrBayesPrint ("                    relevant for clock trees.                                    \n");
11148         MrBayesPrint ("   Clockratepr   -- This parameter specifies the prior assumptions concerning the\n");
11149         MrBayesPrint ("                    base substitution rate of the tree, measured in expected num-\n");
11150         MrBayesPrint ("                    ber of substitutions per site per time unit. The default set-\n");
11151         MrBayesPrint ("                    ting is 'Fixed(1.0)', which effectively means that the time  \n");
11152         MrBayesPrint ("                    unit is the number of expected substitutions per site.       \n");
11153 /*      MrBayesPrint ("                    If you apply age constraints to the tree, the default setting\n");
11154         MrBayesPrint ("                    changes automatically to 'Exponential(<x>)', where '<x>' (the\n");
11155         MrBayesPrint ("                    rate of exponential) is ten times the age of the maximum age \n");
11156         MrBayesPrint ("                    constraint. This will give you a very vague prior, which may \n");
11157         MrBayesPrint ("                    or may not be adequate for your particular problem.          \n"); */
11158         MrBayesPrint ("                    If you do not have any age calibrations in the tree, you can \n");
11159         MrBayesPrint ("                    still calibrate the tree using 'Clockratepr'. For instance,  \n");
11160         MrBayesPrint ("                    if you know that your sequence data evolve at a rate of 0.20 \n");
11161         MrBayesPrint ("                    substitutions per million years, you might calibrate the tree\n");
11162         MrBayesPrint ("                    by fixing the substitution rate to 0.20 using                \n");
11163         MrBayesPrint ("                                                                                 \n");
11164         MrBayesPrint ("                       prset clockratepr = fixed(0.20)                           \n");
11165         MrBayesPrint ("                                                                                 \n");
11166         MrBayesPrint ("                    after which the tree will be calibrated using millions of    \n");
11167         MrBayesPrint ("                    years as the unit.                                           \n");
11168         MrBayesPrint ("                                                                                 \n");
11169         MrBayesPrint ("                    You can also assign a prior probability distribution to the  \n");
11170         MrBayesPrint ("                    substitution rate, accommodating the uncertainty of it.      \n");
11171         MrBayesPrint ("                    When you calibrate the nodes, you should properly set this   \n");
11172         MrBayesPrint ("                    prior to match the time unit of the calibrations.            \n");
11173         MrBayesPrint ("                    You can choose among normal, lognormal, exponential and gamma\n");
11174         MrBayesPrint ("                    distributions for this purpose. For instance, to assign a    \n");
11175         MrBayesPrint ("                    normal distribution truncated at 0, so that only positive    \n");
11176         MrBayesPrint ("                    values are allowed, and with mean 0.20 and standard deviation\n");
11177         MrBayesPrint ("                    of 0.02, you would use                                       \n");
11178         MrBayesPrint ("                                                                                 \n");
11179         MrBayesPrint ("                       prset clockratepr = normal(0.20,0.02)                     \n");
11180         MrBayesPrint ("                                                                                 \n");
11181         MrBayesPrint ("                    The lognormal distribution is parameterized in terms of the  \n");
11182         MrBayesPrint ("                    mean and standard deviation on the log scale (natural logs). \n");
11183         MrBayesPrint ("                    For instance,                                                \n");
11184         MrBayesPrint ("                                                                                 \n");
11185         MrBayesPrint ("                       prset clockratepr = lognormal(-1.61,0.10)                 \n");
11186         MrBayesPrint ("                                                                                 \n");
11187         MrBayesPrint ("                    specifies a lognormal distribution with a mean of log values \n");
11188         MrBayesPrint ("                    of -1.61 and a standard deviation of log values of 0.10. In  \n");
11189         MrBayesPrint ("                    such a case, the mean value of the lognormal distribution is \n");
11190         MrBayesPrint ("                    equal to e^(-1.61 + 0.10^2/2) = 0.20.                        \n");
11191         MrBayesPrint ("                                                                                 \n");
11192         MrBayesPrint ("                    Note that the 'Clockratepr' parameter has no effect on non-  \n");
11193         MrBayesPrint ("                    clock trees.                                                 \n");
11194         MrBayesPrint ("   Clockvarpr    -- This parameter allows you to specify the type of clock you   \n");
11195         MrBayesPrint ("                    are assuming. The default is 'strict', which corresponds to  \n");
11196         MrBayesPrint ("                    the standard clock model where the evolutionary rate is      \n");
11197         MrBayesPrint ("                    constant throughout the tree. For relaxed clock models, you  \n");
11198         MrBayesPrint ("                    can use 'cpp', 'tk02', 'igr'. ('mixed' is not working)       \n");
11199         MrBayesPrint ("                    'cpp' invokes a relaxed clock model where the rate evolves   \n");
11200         MrBayesPrint ("                    according to a Compound Poisson Process (CPP) (Huelsenbeck   \n");
11201         MrBayesPrint ("                    et al., 2000).                                               \n");
11202         MrBayesPrint ("                    'tk02' invokes the Brownian Motion model described by Thorne \n");
11203         MrBayesPrint ("                    and Kishino (2002). [autocorrelated lognormal distributions] \n");
11204         MrBayesPrint ("                    'igr' invokes the Independent Gamma Rate (IGR) model where   \n");
11205         MrBayesPrint ("                    each branch has an independent rate drawn from a gamma       \n");
11206         MrBayesPrint ("                    distribution (LePage et al., 2007).                          \n");
11207         MrBayesPrint ("                    Each of the relaxed clock models has additional parameters   \n");
11208         MrBayesPrint ("                    with priors. For the CPP model, it is 'cppratepr' and        \n");
11209         MrBayesPrint ("                    'cppmultdevpr'; for the TK02 model, it is 'tk02varpr'; for   \n");
11210         MrBayesPrint ("                    the IGR  model, it is 'igrvarpr'.                            \n");
11211         MrBayesPrint ("                    The 'clockvarpr' parameter is only relevant for clock trees. \n");
11212         MrBayesPrint ("                                                                                 \n");
11213         MrBayesPrint ("                    For backward compatibility, 'bm' is allowed as a synonym of  \n");
11214         MrBayesPrint ("                    'tk02', and 'ibr' as a synonym of 'igr'.                     \n");
11215         MrBayesPrint ("   Cppratepr     -- This parameter allows you to specify a prior probability     \n");
11216         MrBayesPrint ("                    distribution on the rate of the Poisson process generating   \n");
11217         MrBayesPrint ("                    changes in the evolutionary rate in the CPP relaxed clock    \n");
11218         MrBayesPrint ("                    model. You can either fix the rate or associate it with an   \n");
11219         MrBayesPrint ("                    exponential prior using                                      \n");
11220         MrBayesPrint ("                                                                                 \n");
11221         MrBayesPrint ("                       prset cppratepr = fixed(<number>)                         \n");
11222         MrBayesPrint ("                       prset cppratepr = exponential(<number>)                   \n");
11223         MrBayesPrint ("                                                                                 \n");
11224         MrBayesPrint ("                    For instance, if you fix the rate to 2, then on a branch     \n");
11225         MrBayesPrint ("                    with the length equual to one expresed in terms of average   \n");
11226         MrBayesPrint ("                    expected number of substitution per site, you expect to see, \n");
11227         MrBayesPrint ("                    on average, two rate-modifying events.                       \n");
11228         MrBayesPrint ("                    If you put an exponential(0.1) on the rate, you will be      \n");
11229         MrBayesPrint ("                    estimating the rate against a prior probability distribution \n");
11230         MrBayesPrint ("                    where the expected rate is 10 (= 1/0.1).                     \n");
11231         MrBayesPrint ("   Cppmultdevpr  -- This parameter allows you to specify the standard deviation  \n");
11232         MrBayesPrint ("                    of the log-normal distribution from which the rate multi-    \n");
11233         MrBayesPrint ("                    pliers of the CPP relaxed clock model are drawn. The standard\n");
11234         MrBayesPrint ("                    deviation is given on the log scale. The default value of 1.0\n");
11235         MrBayesPrint ("                    thus corresponds to rate multipliers varying from 0.37 (1/e) \n");
11236         MrBayesPrint ("                    to 2.7 (e) when they are +/- one standard deviation from the \n");
11237         MrBayesPrint ("                    expected mean. The expected mean of the logarithm of the mul-\n");
11238         MrBayesPrint ("                    pliers is fixed to 0, ensuring that the expected mean rate is\n");
11239         MrBayesPrint ("                    1.0. You can change the default value by using               \n");
11240         MrBayesPrint ("                                                                                 \n");
11241         MrBayesPrint ("                       prset cppmultdevpr = fixed(<number>)                      \n");
11242         MrBayesPrint ("                                                                                 \n");
11243         MrBayesPrint ("                    where <number> is the standard deviation on the log scale.   \n");
11244         MrBayesPrint ("   TK02varpr     -- This parameter allows you to specify the prior probability   \n");
11245         MrBayesPrint ("                    distribution for the variance of the rate multiplier in the  \n");
11246         MrBayesPrint ("                    Thorne-Kishino ('Brownian motion') relaxed clock model.      \n");
11247         MrBayesPrint ("                    Specifically, the parameter specifies the rate at which the  \n");
11248         MrBayesPrint ("                    variance increases with respect to the base rate of the      \n");
11249         MrBayesPrint ("                    clock. If you have a branch of a length corresponding to 0.4 \n");
11250         MrBayesPrint ("                    expected changes per site according to the base rate of the  \n");
11251         MrBayesPrint ("                    clock, and the tk02var parameter has a value of 2.0, then the\n");
11252         MrBayesPrint ("                    rate multiplier at the end of the branch will be drawn from a\n");
11253         MrBayesPrint ("                    lognormal distribution with a variance of 0.4*2.0 (on the    \n");
11254         MrBayesPrint ("                    linear, not the logarithm scale). The mean is the same as the\n");
11255         MrBayesPrint ("                    rate multiplier at the start of the branch (again on the     \n");
11256         MrBayesPrint ("                    linear scale).                                               \n");
11257         MrBayesPrint ("                                                                                 \n");
11258         MrBayesPrint ("                    You can set the parameter to a fixed value, or specify that  \n");
11259         MrBayesPrint ("                    it is drawn from an exponential or uniform distribution:     \n");
11260         MrBayesPrint ("                                                                                 \n");
11261         MrBayesPrint ("                       prset tk02varpr = fixed(<number>)                         \n");
11262         MrBayesPrint ("                       prset tk02varpr = exponential(<number>)                   \n");
11263         MrBayesPrint ("                       prset tk02varpr = uniform(<number>,<number>)              \n");
11264         MrBayesPrint ("                                                                                 \n");
11265         MrBayesPrint ("                    For backward compatibility, 'bmvarpr' is allowed as a synonym\n");
11266         MrBayesPrint ("                    of 'tko2varpr'.                                              \n");
11267         MrBayesPrint ("   Igrvarpr      -- This parameter allows you to specify a prior on the variance \n");
11268         MrBayesPrint ("                    of the gamma distribution from which the branch lengths are  \n");
11269         MrBayesPrint ("                    drawn in the independent branch rate (IGR) relaxed clock     \n");
11270         MrBayesPrint ("                    model. Specifically, the parameter specifies the rate at     \n");
11271         MrBayesPrint ("                    which the variance increases with respect to the base rate of\n");
11272         MrBayesPrint ("                    the clock. If you have a branch of a length corresponding to \n");
11273         MrBayesPrint ("                    0.4 expected changes per site according to the base rate of  \n");
11274         MrBayesPrint ("                    the clock, and the igrvar parameter has a value of 2.0, then \n");
11275         MrBayesPrint ("                    the effective branch length will be drawn from a distribution\n");
11276         MrBayesPrint ("                    with a variance of 0.4*2.0.                                  \n");
11277         MrBayesPrint ("                                                                                 \n");
11278         MrBayesPrint ("                    You can set the parameter to a fixed value, or specify that  \n");
11279         MrBayesPrint ("                    it is drawn from an exponential or uniform distribution:     \n");
11280         MrBayesPrint ("                                                                                 \n");
11281         MrBayesPrint ("                       prset igrvarpr = fixed(<number>)                          \n");
11282         MrBayesPrint ("                       prset igrvarpr = exponential(<number>)                    \n");
11283         MrBayesPrint ("                       prset igrvarpr = uniform(<number>,<number>)               \n");
11284         MrBayesPrint ("                                                                                 \n");
11285         MrBayesPrint ("                    For backward compatibility, 'ibrvarpr' is allowed as a syn-  \n");
11286         MrBayesPrint ("                    onym of 'igrvarpr'.                                          \n");
11287         MrBayesPrint ("   Ratepr        -- This parameter allows you to specify the site specific rates \n");
11288         MrBayesPrint ("                    model or any other model that allows different partitions to \n");
11289         MrBayesPrint ("                    evolve at different rates. First, you must have defined a    \n");
11290         MrBayesPrint ("                    partition of the characters. For example, you may define a   \n");
11291         MrBayesPrint ("                    partition that divides the characters by codon position, if  \n");
11292         MrBayesPrint ("                    you have DNA data. You can also divide your data using a     \n");
11293         MrBayesPrint ("                    partition that separates different genes from each other.    \n");
11294         MrBayesPrint ("                    The next step is to make the desired partition the active one\n");
11295         MrBayesPrint ("                    using the set command. For example, if your partition is     \n");
11296         MrBayesPrint ("                    called \"by_codon\", then you make that the active partition \n");
11297         MrBayesPrint ("                    using \"set partition=by_codon\". Now that you have defined  \n");
11298         MrBayesPrint ("                    and activated a partition, you can specify the rate multi-   \n");
11299         MrBayesPrint ("                    pliers for the various partitions. The options are:          \n");
11300         MrBayesPrint ("                                                                                 \n");
11301         MrBayesPrint ("                       prset ratepr = fixed                                      \n");
11302         MrBayesPrint ("                       prset ratepr = variable                                   \n");
11303         MrBayesPrint ("                       prset ratepr = dirichlet(<number>,<number>,...,<number>)  \n");
11304         MrBayesPrint ("                                                                                 \n");
11305         MrBayesPrint ("                    If you specify \"fixed\", then the rate multiplier for       \n");
11306         MrBayesPrint ("                    that partition is set to 1 (i.e., the rate is fixed to       \n");
11307         MrBayesPrint ("                    the average rate across partitions). On the other hand,      \n");
11308         MrBayesPrint ("                    if you specify \"variable\", then the rate is allowed to     \n");
11309         MrBayesPrint ("                    vary across partitions subject to the constraint that the    \n");
11310         MrBayesPrint ("                    average rate of substitution across the partitions is 1.     \n");
11311         MrBayesPrint ("                    You must specify a variable rate prior for at least two      \n");
11312         MrBayesPrint ("                    partitions, otherwise the option is not activated when       \n");
11313         MrBayesPrint ("                    calculating likelihoods. The variable option automatically   \n");
11314         MrBayesPrint ("                    associates the partition rates with a dirichlet(1,...,1)     \n");
11315         MrBayesPrint ("                    prior. The dirichlet option is an alternative way of setting \n");
11316         MrBayesPrint ("                    a partition rate to be variable, and also gives accurate     \n");
11317         MrBayesPrint ("                    control of the shape of the prior. The parameters of the     \n");
11318         MrBayesPrint ("                    Dirichlet are listed in the order of the partitions that the \n");
11319         MrBayesPrint ("                    ratepr is applied to. For instance, \"prset applyto=(1,3,4)  \n");
11320         MrBayesPrint ("                    ratepr = dirichlet(10,40,15)\" would set the Dirichlet para- \n");
11321         MrBayesPrint ("                    meter 10 to partition 1, 40 to partition 3, and 15 to parti- \n");
11322         MrBayesPrint ("                    tion 4. The Dirichlet distribution is applied to the weighted\n");
11323         MrBayesPrint ("                    rates; that is, it weights the partition rates according to  \n");
11324         MrBayesPrint ("                    the number of included characters in each partition.         \n");
11325         MrBayesPrint ("   Generatepr    -- This parameter is similar to 'Ratepr' but applies to gene    \n");
11326         MrBayesPrint ("                    trees in the multispecies coalescent, whereas 'Ratepr' app-  \n");
11327         MrBayesPrint ("                    lies to partitions within genes.                             \n");
11328         MrBayesPrint ("                                                                                 \n");
11329         if (numCurrentDivisions == 0)
11330             tempInt = 1;
11331         else
11332             tempInt = numCurrentDivisions;
11333         for (i=0; i<tempInt; i++)
11334             {
11335             if (numCurrentDivisions == 0)
11336                 {
11337                 MrBayesPrint ("   Default model settings:                                                       \n");
11338                 mp = &defaultModel;
11339                 }
11340             else
11341                 {
11342                 MrBayesPrint ("   Model settings for partition %d:                                              \n", i+1);
11343                 mp = &modelParams[i];
11344                 }
11345             MrBayesPrint ("                                                                                 \n");
11346             MrBayesPrint ("   Parameter        Options                      Current Setting                 \n");
11347             MrBayesPrint ("   ------------------------------------------------------------------            \n");
11348 
11349             MrBayesPrint ("   Tratiopr         Beta/Fixed                   %s", mp->tRatioPr);
11350             if (!strcmp(mp->tRatioPr, "Beta"))
11351                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->tRatioDir[0], mp->tRatioDir[1]);
11352             else
11353                 MrBayesPrint ("(%1.1lf)\n", mp->tRatioFix);
11354 
11355             MrBayesPrint ("   Revmatpr         Dirichlet/Fixed              %s", mp->revMatPr);
11356             if (!strcmp(mp->revMatPr, "Dirichlet"))
11357                 MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf,%1.1lf,%1.1lf,%1.1lf)\n", mp->revMatDir[0],
11358                 mp->revMatDir[1], mp->revMatDir[2], mp->revMatDir[3],
11359                 mp->revMatDir[4], mp->revMatDir[5]);
11360             else
11361                 MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf,%1.1lf,%1.1lf,%1.1lf)\n", mp->revMatFix[0],
11362                 mp->revMatFix[1], mp->revMatFix[2], mp->revMatFix[3],
11363                 mp->revMatFix[4], mp->revMatFix[5]);
11364 
11365             MrBayesPrint ("   Aamodelpr        Fixed/Mixed                  %s", mp->aaModelPr);
11366             if (!strcmp(mp->aaModelPr, "Fixed"))
11367                 MrBayesPrint ("(%s)\n", mp->aaModel);
11368             else
11369                 MrBayesPrint ("\n");
11370 
11371             MrBayesPrint ("   Aarevmatpr       Dirichlet/Fixed              %s", mp->aaRevMatPr);
11372             if (!strcmp(mp->aaRevMatPr, "Dirichlet"))
11373                 {
11374                 for (j=1; j<190; j++)
11375                     if (AreDoublesEqual (mp->aaRevMatDir[0], mp->aaRevMatDir[j], 0.00001) == NO)
11376                         break;
11377                 if (j==190)
11378                     MrBayesPrint ("(%1.1lf,%1.1lf,...)\n", mp->aaRevMatDir[0], mp->aaRevMatDir[0]);
11379                 else
11380                     MrBayesPrint (" (use 'Showmodel' to see values set by user)\n");
11381                 }
11382             else
11383                 {
11384                 for (j=1; j<190; j++)
11385                     if (AreDoublesEqual (mp->aaRevMatFix[0], mp->aaRevMatFix[j], 0.00001) == NO)
11386                         break;
11387                 if (j==190)
11388                     MrBayesPrint ("(%1.1lf,%1.1lf,...)\n", mp->aaRevMatFix[0], mp->aaRevMatFix[0]);
11389                 else
11390                     MrBayesPrint (" (use 'Showmodel' to see values set by user)\n");
11391                 }
11392 
11393             MrBayesPrint ("   Omegapr          Dirichlet/Fixed              %s", mp->omegaPr);
11394             if (!strcmp(mp->omegaPr, "Dirichlet"))
11395                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->omegaDir[0], mp->omegaDir[1]);
11396             else
11397                 MrBayesPrint ("(%1.1lf)\n", mp->omegaFix);
11398 
11399             MrBayesPrint ("   Ny98omega1pr     Beta/Fixed                   %s", mp->ny98omega1pr);
11400             if (!strcmp(mp->ny98omega1pr, "Beta"))
11401                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->ny98omega1Beta[0], mp->ny98omega1Beta[1]);
11402             else if (!strcmp(mp->ny98omega1pr, "Fixed"))
11403                 MrBayesPrint ("(%1.1lf)\n", mp->ny98omega1Fixed);
11404 
11405             MrBayesPrint ("   Ny98omega3pr     Uniform/Exponential/Fixed    %s", mp->ny98omega3pr);
11406             if (!strcmp(mp->ny98omega3pr, "Uniform"))
11407                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->ny98omega3Uni[0], mp->ny98omega3Uni[1]);
11408             else if (!strcmp(mp->ny98omega3pr, "Exponential"))
11409                 MrBayesPrint ("(%1.1lf)\n", mp->ny98omega3Exp);
11410             else
11411                 MrBayesPrint ("(%1.1lf)\n", mp->ny98omega3Fixed);
11412 
11413             MrBayesPrint ("   M3omegapr        Exponential/Fixed            %s", mp->m3omegapr);
11414             if (!strcmp(mp->m3omegapr, "Exponential"))
11415                 MrBayesPrint ("\n");
11416             else if (!strcmp(mp->m3omegapr, "Fixed"))
11417                 MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf)\n", mp->m3omegaFixed[0], mp->m3omegaFixed[1], mp->m3omegaFixed[2]);
11418 
11419             MrBayesPrint ("   Codoncatfreqs    Dirichlet/Fixed              %s", mp->codonCatFreqPr);
11420             if (!strcmp(mp->codonCatFreqPr, "Dirichlet"))
11421                 MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf)\n", mp->codonCatDir[0], mp->codonCatDir[1], mp->codonCatDir[2]);
11422             else
11423                 MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf)\n", mp->codonCatFreqFix[0], mp->codonCatFreqFix[1], mp->codonCatFreqFix[2]);
11424 
11425             MrBayesPrint ("   Statefreqpr      Dirichlet/Fixed              %s", mp->stateFreqPr);
11426             if (!strcmp(mp->stateFreqPr, "Dirichlet"))
11427                 {
11428                 if (mp->dataType == DNA || mp->dataType == RNA)
11429                     {
11430                     if (!strcmp(mp->nucModel, "4by4"))
11431                         MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf,%1.1lf)\n", mp->stateFreqsDir[0], mp->stateFreqsDir[1],
11432                             mp->stateFreqsDir[2], mp->stateFreqsDir[3]);
11433                     else
11434                         MrBayesPrint ("\n");
11435                     }
11436                 else if (mp->dataType == RESTRICTION)
11437                     {
11438                     MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->stateFreqsDir[0], mp->stateFreqsDir[1]);
11439                     }
11440                 else
11441                     MrBayesPrint ("\n");
11442                 }
11443             else if (!strcmp(mp->stateFreqPr, "Fixed"))
11444                 {
11445                 if (mp->dataType == DNA || mp->dataType == RNA)
11446                     {
11447                     if (!strcmp(mp->nucModel, "4by4"))
11448                         MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf,%1.1lf)\n", mp->stateFreqsFix[0], mp->stateFreqsFix[1],
11449                             mp->stateFreqsFix[2], mp->stateFreqsFix[3]);
11450                     else
11451                         MrBayesPrint ("\n");
11452                     }
11453                 else if (mp->dataType == RESTRICTION)
11454                     {
11455                     MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->stateFreqsFix[0], mp->stateFreqsFix[1]);
11456                     }
11457                 else
11458                     MrBayesPrint ("\n");
11459                 }
11460 
11461             MrBayesPrint ("   Shapepr          Uniform/Exponential/Fixed    %s", mp->shapePr);
11462             if (!strcmp(mp->shapePr, "Uniform"))
11463                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->shapeUni[0], mp->shapeUni[1]);
11464             else if (!strcmp(mp->shapePr, "Exponential"))
11465                 MrBayesPrint ("(%1.1lf)\n", mp->shapeExp);
11466             else
11467                 MrBayesPrint ("(%1.1lf)\n", mp->shapeFix);
11468 
11469             MrBayesPrint ("   Ratecorrpr       Uniform/Fixed                %s", mp->adGammaCorPr);
11470             if (!strcmp(mp->adGammaCorPr, "Uniform"))
11471                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->corrUni[0], mp->corrUni[1]);
11472             else
11473                 MrBayesPrint ("(%1.1lf)\n", mp->corrFix);
11474 
11475             MrBayesPrint ("   Pinvarpr         Uniform/Fixed                %s", mp->pInvarPr);
11476             if (!strcmp(mp->pInvarPr, "Uniform"))
11477                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->pInvarUni[0], mp->pInvarUni[1]);
11478             else
11479                 MrBayesPrint ("(%1.1lf)\n", mp->pInvarFix);
11480 
11481             MrBayesPrint ("   Covswitchpr      Uniform/Exponential/Fixed    %s", mp->covSwitchPr);
11482             if (!strcmp(mp->covSwitchPr, "Uniform"))
11483                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->covswitchUni[0], mp->covswitchUni[1]);
11484             else if (!strcmp(mp->covSwitchPr, "Exponential"))
11485                 MrBayesPrint ("(%1.1lf)\n", mp->covswitchExp);
11486             else
11487                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->covswitchFix[0], mp->covswitchFix[1]);
11488 
11489             MrBayesPrint ("   Symdirihyperpr   Uniform/Exponential/Fixed    %s", mp->symPiPr);
11490             if (!strcmp(mp->symPiPr, "Uniform"))
11491                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->symBetaUni[0], mp->symBetaUni[1]);
11492             else if (!strcmp(mp->covSwitchPr, "Exponential"))
11493                 MrBayesPrint ("(%1.1lf)\n", mp->symBetaExp);
11494             else
11495                 {
11496                 if (mp->symBetaFix < 0)
11497                     MrBayesPrint ("(Infinity)\n");
11498                 else
11499                     MrBayesPrint ("(%1.1lf)\n", mp->symBetaFix);
11500                 }
11501 
11502             MrBayesPrint ("   Topologypr       Uniform/Constraints/Fixed/   %s", mp->topologyPr);
11503             if (!strcmp(mp->topologyPr, "Constraints"))
11504                 {
11505                 MrBayesPrint ("(");
11506                 for (j=0; j<numDefinedConstraints; j++)
11507                     {
11508                     if (mp->activeConstraints[j] == YES)
11509                         {
11510                         MrBayesPrint ("%d", j+1);
11511                         break;
11512                         }
11513                     }
11514                for (j++; j<numDefinedConstraints; j++)
11515                     {
11516                     if (mp->activeConstraints[j] == YES)
11517                         {
11518                         MrBayesPrint (",%d", j+1);
11519                         }
11520                     }
11521                 MrBayesPrint (")\n");
11522                 }
11523             else if (!strcmp(mp->topologyPr, "Fixed"))
11524                 MrBayesPrint("(%s)\n", userTree[mp->topologyFix]->name);
11525             else
11526                 MrBayesPrint ("\n");
11527             MrBayesPrint ("                    Speciestree                  \n");
11528 
11529             MrBayesPrint ("   Brlenspr         Unconstrained/Clock/Fixed    %s", mp->brlensPr);
11530             if (!strcmp(mp->brlensPr, "Unconstrained"))
11531                 {
11532                 if (!strcmp(mp->unconstrainedPr, "Uniform"))
11533                     MrBayesPrint (":Uni(%1.1lf,%1.1lf)\n", mp->brlensUni[0], mp->brlensUni[1]);
11534                 else if (!strcmp(mp->unconstrainedPr, "GammaDir"))
11535                     MrBayesPrint (":GammaDir(%1.1lf,%1.3lf,%1.1lf,%1.1lf)\n",
11536                                 mp->brlensDir[0], mp->brlensDir[1], mp->brlensDir[2], mp->brlensDir[3]);
11537                 else if (!strcmp(mp->unconstrainedPr, "invGamDir"))
11538                     MrBayesPrint (":invGamDir(%1.1lf,%1.3lf,%1.1lf,%1.1lf)\n",
11539                                 mp->brlensDir[0], mp->brlensDir[1], mp->brlensDir[2], mp->brlensDir[3]);
11540                 else if (!strcmp(mp->unconstrainedPr, "twoExp"))
11541                     MrBayesPrint (":twoExp(%1.1lf,%1.1lf)\n", mp->brlens2Exp[0], mp->brlens2Exp[1]);
11542                 else
11543                     MrBayesPrint (":Exp(%1.1lf)\n", mp->brlensExp);
11544                 }
11545             else if (!strcmp(mp->brlensPr, "Clock"))
11546                 {
11547                 if (!strcmp(mp->clockPr,"Fixed"))
11548                     MrBayesPrint (":%s(%s)\n", mp->clockPr, userTree[mp->brlensFix]->name);
11549                 else
11550                     MrBayesPrint (":%s\n", mp->clockPr);
11551                 }
11552             else if (!strcmp(mp->brlensPr, "Fixed"))
11553                 MrBayesPrint("(%s)\n", userTree[mp->brlensFix]->name);
11554 
11555             MrBayesPrint ("   Treeagepr        Gamma/Uniform/Fixed/         %s\n", mp->treeAgePr.name);
11556             MrBayesPrint ("                    Truncatednormal/Lognormal/   \n");
11557             MrBayesPrint ("                    Offsetlognormal/Offsetgamma/ \n");
11558             MrBayesPrint ("                    Offsetexponential            \n");
11559 
11560             MrBayesPrint ("   Speciationpr     Uniform/Exponential/Fixed    %s", mp->speciationPr);
11561             if (!strcmp(mp->speciationPr, "Uniform"))
11562                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->speciationUni[0], mp->speciationUni[1]);
11563             else if (!strcmp(mp->speciationPr, "Exponential"))
11564                 MrBayesPrint ("(%1.1lf)\n", mp->speciationExp);
11565             else
11566                 MrBayesPrint ("(%1.1lf)\n", mp->speciationFix);
11567 
11568             MrBayesPrint ("   Extinctionpr     Beta/Fixed                   %s", mp->extinctionPr);
11569             if (!strcmp(mp->extinctionPr, "Beta"))
11570                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->extinctionBeta[0], mp->extinctionBeta[1]);
11571             else
11572                 MrBayesPrint ("(%1.1lf)\n", mp->extinctionFix);
11573 
11574             MrBayesPrint ("   Fossilizationpr  Beta/Fixed                   %s", mp->fossilizationPr);
11575             if (!strcmp(mp->fossilizationPr, "Beta"))
11576                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->fossilizationBeta[0], mp->fossilizationBeta[1]);
11577             else
11578                 MrBayesPrint ("(%1.2lf)\n", mp->fossilizationFix);
11579 
11580             MrBayesPrint ("   SampleStrat      Random/Diversity/Cluster/    %s\n", mp->sampleStrat);
11581             MrBayesPrint ("                    FossilTip                    \n");
11582             // if (!strcmp(mp->sampleStrat, "Random") || !strcmp(mp->sampleStrat, "Diversity"))
11583 
11584             MrBayesPrint ("   Sampleprob       <number>                     %1.8lf\n", mp->sampleProb);
11585 
11586             MrBayesPrint ("   Popsizepr        Lognormal/Gamma/Uniform/     %s", mp->popSizePr);
11587             if (!strcmp(mp->popSizePr, "Uniform"))
11588                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->popSizeUni[0], mp->popSizeUni[1]);
11589             else if (!strcmp(mp->popSizePr, "Lognormal"))
11590                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->popSizeLognormal[0], mp->popSizeLognormal[1]);
11591             else if (!strcmp(mp->popSizePr, "Normal"))
11592                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->popSizeNormal[0], mp->popSizeNormal[1]);
11593             else if (!strcmp(mp->popSizePr, "Gamma"))
11594                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->popSizeGamma[0], mp->popSizeGamma[1]);
11595             else
11596                 MrBayesPrint ("(%1.1lf)\n", mp->popSizeFix);
11597             MrBayesPrint ("                    Normal/Fixed                 \n");
11598 
11599             MrBayesPrint ("   Popvarpr         Equal/Variable               %s\n", mp->popVarPr);
11600 
11601             /*
11602             MrBayesPrint ("   Growthpr         Uniform/Exponential/         \n");
11603             MrBayesPrint ("                    Fixed/Normal                 %s", mp->growthPr);
11604             if (!strcmp(mp->growthPr, "Uniform"))
11605                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->growthUni[0], mp->growthUni[1]);
11606             else if (!strcmp(mp->growthPr, "Exponential"))
11607                 MrBayesPrint ("(%1.1lf)\n", mp->growthExp);
11608             else if (!strcmp(mp->growthPr, "Normal"))
11609                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->growthNorm[0], mp->growthNorm[1]);
11610             else
11611                 MrBayesPrint ("(%1.1lf)\n", mp->growthFix);
11612             */
11613 
11614             MrBayesPrint ("   Nodeagepr        Unconstrained/Calibrated     %s\n", mp->nodeAgePr);
11615 
11616             MrBayesPrint ("   Clockratepr      Fixed/Normal/Lognormal/      %s", mp->clockRatePr);
11617             if (!strcmp(mp->clockRatePr, "Fixed"))
11618                 MrBayesPrint ("(%1.2lf)\n", mp->clockRateFix);
11619             else if (!strcmp(mp->clockRatePr,"Exponential"))
11620                 MrBayesPrint ("(%1.2lf)\n", mp->clockRateExp);
11621             else if (!strcmp(mp->clockRatePr,"Normal"))
11622                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->clockRateNormal[0], mp->clockRateNormal[1]);
11623             else if (!strcmp(mp->clockRatePr,"Lognormal"))
11624                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->clockRateLognormal[0], mp->clockRateLognormal[1]);
11625             else
11626                 {
11627                 assert (!strcmp(mp->clockRatePr,"Gamma"));
11628                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->clockRateGamma[0], mp->clockRateGamma[1]);
11629                 }
11630             MrBayesPrint ("                    Exponential/Gamma            \n");
11631 
11632             MrBayesPrint ("   Clockvarpr       Strict/Cpp/TK02/Igr/Mixed    %s\n", mp->clockVarPr);
11633 
11634             MrBayesPrint ("   Cppratepr        Fixed/Exponential            %s", mp->cppRatePr);
11635             if (!strcmp(mp->cppRatePr, "Fixed"))
11636                 MrBayesPrint ("(%1.2lf)\n", mp->cppRateFix);
11637             else /* if (!strcmp(mp->cppRatePr,"Exponential")) */
11638                 MrBayesPrint ("(%1.2lf)\n", mp->cppRateExp);
11639 
11640             MrBayesPrint ("   Cppmultdevpr     Fixed                        %s", mp->cppMultDevPr);
11641             MrBayesPrint ("(%1.2lf)\n", mp->cppMultDevFix);
11642 
11643             MrBayesPrint ("   TK02varpr        Fixed/Exponential/Uniform    %s", mp->tk02varPr);
11644             if (!strcmp(mp->tk02varPr, "Fixed"))
11645                 MrBayesPrint ("(%1.2lf)\n", mp->tk02varFix);
11646             else if (!strcmp(mp->tk02varPr,"Exponential"))
11647                 MrBayesPrint ("(%1.2lf)\n", mp->tk02varExp);
11648             else
11649                 {
11650                 assert (!strcmp(mp->tk02varPr,"Uniform"));
11651                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->tk02varUni[0], mp->tk02varUni[1]);
11652                 }
11653 
11654             MrBayesPrint ("   Igrvarpr         Fixed/Exponential/Uniform    %s", mp->igrvarPr);
11655             if (!strcmp(mp->igrvarPr, "Fixed"))
11656                 MrBayesPrint ("(%1.2lf)\n", mp->igrvarFix);
11657             else if (!strcmp(mp->igrvarPr,"Exponential"))
11658                 MrBayesPrint ("(%1.2lf)\n", mp->igrvarExp);
11659             else
11660                 {
11661                 assert (!strcmp(mp->igrvarPr,"Uniform"));
11662                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->igrvarUni[0], mp->igrvarUni[1]);
11663                 }
11664 
11665             /*  MrBayesPrint ("   Mixedvarpr       Fixed/Exponential/Uniform    %s", mp->mixedvarPr);
11666             if (!strcmp(mp->mixedvarPr, "Fixed"))
11667                 MrBayesPrint ("(%1.2lf)\n", mp->mixedvarFix);
11668             else if (!strcmp(mp->mixedvarPr,"Exponential"))
11669                 MrBayesPrint ("(%1.2lf)\n", mp->mixedvarExp);
11670             else
11671                 {
11672                 assert (!strcmp(mp->mixedvarPr,"Uniform"));
11673                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->mixedvarUni[0], mp->mixedvarUni[1]);
11674                 }  */
11675 
11676             MrBayesPrint ("   Ratepr           Fixed/Variable=Dirichlet     %s", mp->ratePr);
11677             if (!strcmp(mp->ratePr, "Dirichlet"))
11678                 MrBayesPrint ("(...,%1.1lf,...)\n", mp->ratePrDir);
11679             else
11680                 MrBayesPrint ("\n");
11681 
11682             MrBayesPrint ("   Generatepr       Fixed/Variable=Dirichlet     %s", mp->generatePr);
11683             if (!strcmp(mp->generatePr, "Dirichlet"))
11684                 MrBayesPrint ("(...,%1.1lf,...)\n", mp->generatePrDir);
11685             else
11686                 MrBayesPrint ("\n");
11687 
11688             MrBayesPrint ("                                                                                 \n");
11689             MrBayesPrint ("   ------------------------------------------------------------------            \n");
11690             }
11691         }
11692     else if (!strcmp(helpTkn, "Ctype"))
11693         {
11694         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11695         MrBayesPrint ("   Ctype                                                                         \n");
11696         MrBayesPrint ("                                                                                 \n");
11697         MrBayesPrint ("   This command sets the character ordering for standard-type data. The          \n");
11698         MrBayesPrint ("   correct usage is:                                                             \n");
11699         MrBayesPrint ("                                                                                 \n");
11700         MrBayesPrint ("      ctype <ordering>:<characters>                                              \n");
11701         MrBayesPrint ("                                                                                 \n");
11702         MrBayesPrint ("   The available options for the <ordering> specifier are:                       \n");
11703         MrBayesPrint ("                                                                                 \n");
11704         MrBayesPrint ("     unordered    -- Movement directly from one state to another is              \n");
11705         MrBayesPrint ("                     allowed in an instant of time.                              \n");
11706         MrBayesPrint ("     ordered      -- Movement is only allowed between adjacent characters.       \n");
11707         MrBayesPrint ("                     For example, perhaps only between 0 <-> 1 and 1 <-> 2       \n");
11708         MrBayesPrint ("                     for a three state character ordered as 0 - 1 - 2.           \n");
11709         MrBayesPrint ("     irreversible -- Rates of change for losses are 0.                           \n");
11710         MrBayesPrint ("                                                                                 \n");
11711         MrBayesPrint ("   The characters to which the ordering is applied is specified in manner        \n");
11712         MrBayesPrint ("   that is identical to commands such as \"include\" or \"exclude\". For         \n");
11713         MrBayesPrint ("   example,                                                                      \n");
11714         MrBayesPrint ("                                                                                 \n");
11715         MrBayesPrint ("      ctype ordered: 10 23 45                                                    \n");
11716         MrBayesPrint ("                                                                                 \n");
11717         MrBayesPrint ("   defines charactes 10, 23, and 45 to be of type ordered. Similarly,            \n");
11718         MrBayesPrint ("                                                                                 \n");
11719         MrBayesPrint ("      ctype irreversible: 54-67  71-92                                           \n");
11720         MrBayesPrint ("                                                                                 \n");
11721         MrBayesPrint ("   defines characters 54 to 67 and characters 71 to 92 to be of type             \n");
11722         MrBayesPrint ("   irreversible. You can use the \".\" to denote the last character, and         \n");
11723         MrBayesPrint ("   \"all\" to denote all of the characters. Finally, you can use the             \n");
11724         MrBayesPrint ("   specifier \"\\\" to apply the ordering to every n-th character or             \n");
11725         MrBayesPrint ("   you can use predefined charsets to specify the character.                     \n");
11726         MrBayesPrint ("                                                                                 \n");
11727         MrBayesPrint ("   Only one ordering can be used on any specific application of ctype.           \n");
11728         MrBayesPrint ("   If you want to apply different orderings to different characters, then        \n");
11729         MrBayesPrint ("   you need to use ctype multiple times. For example,                            \n");
11730         MrBayesPrint ("                                                                                 \n");
11731         MrBayesPrint ("      ctype ordered: 1-50                                                        \n");
11732         MrBayesPrint ("      ctype irreversible: 51-100                                                 \n");
11733         MrBayesPrint ("                                                                                 \n");
11734         MrBayesPrint ("   sets characters 1 to 50 to be ordered and characters 51 to 100 to be          \n");
11735         MrBayesPrint ("   irreversible.                                                                 \n");
11736         MrBayesPrint ("                                                                                 \n");
11737         MrBayesPrint ("   The ctype command is only sensible with morphological (here called            \n");
11738         MrBayesPrint ("   \"standard\") characters. The program ignores attempts to apply char-         \n");
11739         MrBayesPrint ("   acter orderings to other types of characters, such as DNA characters.         \n");
11740 
11741         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11742         }
11743     else if (!strcmp(helpTkn, "Propset"))
11744         {
11745         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11746         MrBayesPrint ("   Propset                                                                       \n");
11747         MrBayesPrint ("                                                                                 \n");
11748         MrBayesPrint ("   This command allows the user to change the details of the MCMC samplers       \n");
11749         MrBayesPrint ("   (moves) that update the state of the chain. The useage is:                    \n");
11750         MrBayesPrint ("                                                                                 \n");
11751         MrBayesPrint ("      propset  <move_name>$<tuning-parameter>=<value>                            \n");
11752         MrBayesPrint ("                                                                                 \n");
11753         MrBayesPrint ("   Assume we have a topology parameter called 'Tau{all}', which is sampled by    \n");
11754         MrBayesPrint ("   the move 'ExtTBR(Tau{all})' (note that the parameter name is included in the  \n");
11755         MrBayesPrint ("   move name). This move has three tuning parameters: (1) 'prob', the relative   \n");
11756         MrBayesPrint ("   proposal probability (a weight defining its probability relative to other     \n");
11757         MrBayesPrint ("   moves); (2) 'p_ext', the extension probability; and (3) 'lambda', the tuning  \n");
11758         MrBayesPrint ("   parameter of the branch length multiplier. A list of the tuning parameters is \n");
11759         MrBayesPrint ("   available by using 'Showmoves' (see below). To change the relative proposal   \n");
11760         MrBayesPrint ("   probability to 20 and the extension probability to 0.7, use:                  \n");
11761         MrBayesPrint ("                                                                                 \n");
11762         MrBayesPrint ("      propset etbr(tau{all})$prob=20 etbr(tau{all})$p_ext=0.7                    \n");
11763         MrBayesPrint ("                                                                                 \n");
11764         MrBayesPrint ("   This change would apply to all chains in all runs. It is also possible to set \n");
11765         MrBayesPrint ("   the tuning parameters of individual runs and chains using the format:         \n");
11766         MrBayesPrint ("                                                                                 \n");
11767         MrBayesPrint ("      propset  <move_name>$<tuning-parameter>(<run>,<chain>)=<value>             \n");
11768         MrBayesPrint ("                                                                                 \n");
11769         MrBayesPrint ("   where <run> and <chain> are the index numbers of the run and chain for which  \n");
11770         MrBayesPrint ("   you want to change the value. If you leave out the index of the run, the      \n");
11771         MrBayesPrint ("   change will apply to all runs; if you leave out the index of the chain, the   \n");
11772         MrBayesPrint ("   change will similarly apply to all chains. To switch off the exttbr(tau{all}) \n");
11773         MrBayesPrint ("   move in chain 2 of all runs, use:                                             \n");
11774         MrBayesPrint ("                                                                                 \n");
11775         MrBayesPrint ("      propset  etbr(tau{all})$prob(,2)=0                                         \n");
11776         MrBayesPrint ("                                                                                 \n");
11777         MrBayesPrint ("   It is important to note that all moves are not available until the model has  \n");
11778         MrBayesPrint ("   been completely defined. Any change to the model will cause all proposal      \n");
11779         MrBayesPrint ("   tuning parameters to return to their default values. To see a list of all the \n");
11780         MrBayesPrint ("   moves that are currently switched on for the model, use 'showmoves'. You can  \n");
11781         MrBayesPrint ("   also see other available moves by using 'showmoves allavailable=yes'. A list  \n");
11782         MrBayesPrint ("   of the moves for each parameter in the model is available by using the command\n");
11783         MrBayesPrint ("   'Showparams'. If you change proposal probabilities, make sure that all        \n");
11784         MrBayesPrint ("   parameters that are not fixed in your model have at least one move switched   \n");
11785         MrBayesPrint ("   on.                                                                           \n");
11786         MrBayesPrint ("                                                                                 \n");
11787         MrBayesPrint ("   One word of warning: You should be extremely careful when modifying any       \n");
11788         MrBayesPrint ("   of the chain parameters using 'propset'. It is quite possible to completely   \n");
11789         MrBayesPrint ("   wreck any hope of achieving convergence by inappropriately setting the        \n");
11790         MrBayesPrint ("   tuning parameters. In general, you want to set move tuning parameters such    \n");
11791         MrBayesPrint ("   that the acceptance rate of the move is intermediate (we suggest targeting    \n");
11792         MrBayesPrint ("   the range 10%% to 70%% acceptance, if possible). If the acceptance rate is    \n");
11793         MrBayesPrint ("   outside of this range, the MCMC chain will probably not sample that parameter \n");
11794         MrBayesPrint ("   very efficiently. The acceptance rates for all moves in the cold chain(s) are \n");
11795         MrBayesPrint ("   summarized at the end of each run in the screen output. The acceptance rates  \n");
11796         MrBayesPrint ("   (potentially for all chains, cold and heated) are also printed to the .mcmc   \n");
11797         MrBayesPrint ("   file if Mcmc convergence diagnostics are turned on (using 'Mcmc' or 'Mcmcp'). \n");
11798         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11799         }
11800     else if (!strcmp(helpTkn, "Log"))
11801         {
11802         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11803         MrBayesPrint ("   Log                                                                           \n");
11804         MrBayesPrint ("                                                                                 \n");
11805         MrBayesPrint ("   This command allows output to the screen to also be output to a file.         \n");
11806         MrBayesPrint ("   The useage is:                                                                \n");
11807         MrBayesPrint ("                                                                                 \n");
11808         MrBayesPrint ("      log start/stop filename=<name> append/replace                              \n");
11809         MrBayesPrint ("                                                                                 \n");
11810         MrBayesPrint ("   The options are:                                                              \n");
11811         MrBayesPrint ("                                                                                 \n");
11812         MrBayesPrint ("   Start/Stop     -- Starts or stops logging of output to file.                  \n");
11813         MrBayesPrint ("   Append/Replace -- Either append to or replace existing file.                  \n");
11814         MrBayesPrint ("   Filename       -- Name of log file (currently, the name of the log            \n");
11815         MrBayesPrint ("                     file is \"%s\").\n", logFileName);
11816         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11817         }
11818     else if (!strcmp(helpTkn, "Translate"))
11819         {
11820         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11821         MrBayesPrint ("   Translate                                                                     \n");
11822         MrBayesPrint ("                                                                                 \n");
11823         MrBayesPrint ("   This command is used by MrBayes to specify the mapping between taxon names    \n");
11824         MrBayesPrint ("   and taxon numbers in a Nexus tree file. For instance,                         \n");
11825         MrBayesPrint ("                                                                                 \n");
11826         MrBayesPrint ("      translate                                                                  \n");
11827         MrBayesPrint ("         1 Homo,                                                                 \n");
11828         MrBayesPrint ("         2 Pan,                                                                  \n");
11829         MrBayesPrint ("         3 Gorilla,                                                              \n");
11830         MrBayesPrint ("         4 Hylobates;                                                            \n");
11831         MrBayesPrint ("                                                                                 \n");
11832         MrBayesPrint ("   establishes that the taxon labeled 1 in the trees that follow is Homo, the    \n");
11833         MrBayesPrint ("   taxon labeled 2 is Pan, etc.                                                  \n");
11834         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11835         }
11836     else if (!strcmp(helpTkn, "Usertree"))
11837         {
11838         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11839         MrBayesPrint ("   Usertree                                                                      \n");
11840         MrBayesPrint ("                                                                                 \n");
11841         MrBayesPrint ("   This command allows you to specify a user tree. The user tree can then be     \n");
11842         MrBayesPrint ("   used as a starting tree for a MCMC analysis. The format for the command is    \n");
11843         MrBayesPrint ("                                                                                 \n");
11844         MrBayesPrint ("      usertree = <tree in Newick format>                                         \n");
11845         MrBayesPrint ("                                                                                 \n");
11846         MrBayesPrint ("   For example,                                                                  \n");
11847         MrBayesPrint ("                                                                                 \n");
11848         MrBayesPrint ("      usertree = (A,B,(C,D))                                                     \n");
11849         MrBayesPrint ("                                                                                 \n");
11850         MrBayesPrint ("   specifies an unrooted tree of four species. Note that the program re-         \n");
11851         MrBayesPrint ("   quires that trees are binary (i.e., strictly bifurcating). Hence, there       \n");
11852         MrBayesPrint ("   can be only one three-way split, as shown in the example. If the tree         \n");
11853         MrBayesPrint ("   is not binary, the program will return an error.                              \n");
11854         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11855         }
11856     else if (!strcmp(helpTkn, "Mcmc"))
11857         {
11858         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11859         MrBayesPrint ("   Mcmc                                                                          \n");
11860         MrBayesPrint ("                                                                                 \n");
11861         MrBayesPrint ("   This command starts the Markov chain Monte Carlo (MCMC) analysis. The         \n");
11862         MrBayesPrint ("   posterior probability of phylogenetic trees (and other parameters of the      \n");
11863         MrBayesPrint ("   substitution model) cannot be determined analytically. Instead, MCMC is       \n");
11864         MrBayesPrint ("   used to approximate the posterior probabilities of trees by drawing           \n");
11865         MrBayesPrint ("   (dependent) samples from the posterior distribution. This program can         \n");
11866         MrBayesPrint ("   implement a variant of MCMC called \"Metropolis-coupled Markov chain Monte    \n");
11867         MrBayesPrint ("   Carlo\", or MCMCMC for short. Basically, \"Nchains\" are run, with            \n");
11868         MrBayesPrint ("   Nchains - 1 of them heated. The chains are labelled 1, 2, ..., Nchains.       \n");
11869         MrBayesPrint ("   The heat that is applied to the i-th chain is B = 1 / (1 + temp X i). B       \n");
11870         MrBayesPrint ("   is the power to which the posterior probability is raised. When B = 0, all    \n");
11871         MrBayesPrint ("   trees have equal probability and the chain freely visits trees. B = 1 is      \n");
11872         MrBayesPrint ("   the \"cold\" chain (or the distribution of interest). MCMCMC can mix          \n");
11873         MrBayesPrint ("   better than ordinary MCMC; after all of the chains have gone through          \n");
11874         MrBayesPrint ("   one cycle, two chains are chosen at random and an attempt is made to          \n");
11875         MrBayesPrint ("   swap the states (with the probability of a swap being determined by the       \n");
11876         MrBayesPrint ("   Metropolis et al. equation). This allows the chain to potentially jump        \n");
11877         MrBayesPrint ("   a valley in a single bound. The correct usage is                              \n");
11878         MrBayesPrint ("                                                                                 \n");
11879         MrBayesPrint ("      mcmc <parameter> = <value> ... <parameter> = <value>                       \n");
11880         MrBayesPrint ("                                                                                 \n");
11881         MrBayesPrint ("   For example,                                                                  \n");
11882         MrBayesPrint ("                                                                                 \n");
11883         MrBayesPrint ("      mcmc ngen=100000 nchains=4 temp=0.5                                        \n");
11884         MrBayesPrint ("                                                                                 \n");
11885         MrBayesPrint ("   performs a MCMCMC analysis with four chains with the temperature set to       \n");
11886         MrBayesPrint ("   0.5. The chains would be run for 100,000 cycles.                              \n");
11887         MrBayesPrint ("                                                                                 \n");
11888         MrBayesPrint ("   Options:                                                                      \n");
11889         MrBayesPrint ("                                                                                 \n");
11890         MrBayesPrint ("   Ngen         -- This option sets the number of cycles for the MCMC alg-       \n");
11891         MrBayesPrint ("                   orithm. This should be a big number as you want the chain     \n");
11892         MrBayesPrint ("                   to first reach stationarity, and then remain there for        \n");
11893         MrBayesPrint ("                   enough time to take lots of samples.                          \n");
11894         MrBayesPrint ("   Nruns        -- How many independent analyses are started simultaneously.     \n");
11895         MrBayesPrint ("   Nchains      -- How many chains are run for each analysis for the MCMCMC      \n");
11896         MrBayesPrint ("                   variant. The default is 4: 1 cold chain and 3 heated chains.  \n");
11897         MrBayesPrint ("                   If Nchains is set to 1, MrBayes will use regular MCMC sam-    \n");
11898         MrBayesPrint ("                   pling, without heating.                                       \n");
11899         MrBayesPrint ("   Temp         -- The temperature parameter for heating the chains. The higher  \n");
11900         MrBayesPrint ("                   the temperature, the more likely the heated chains are to     \n");
11901         MrBayesPrint ("                   move between isolated peaks in the posterior distribution.    \n");
11902         MrBayesPrint ("                   However, excessive heating may lead to very low acceptance    \n");
11903         MrBayesPrint ("                   rates for swaps between different chains. Before changing the \n");
11904         MrBayesPrint ("                   default setting, however, note that the acceptance rates of   \n");
11905         MrBayesPrint ("                   swaps tend to fluctuate during the burn-in phase of the run.  \n");
11906         MrBayesPrint ("   Reweight     -- Here, you specify three numbers, that respectively represent  \n");
11907         MrBayesPrint ("                   the percentage of characters to decrease in weight, the       \n");
11908         MrBayesPrint ("                   percentage of characters to increase in weight, and the       \n");
11909         MrBayesPrint ("                   increment. An increase/decrease in weight is achieved by      \n");
11910         MrBayesPrint ("                   replicating/removing a character in the matrix. This is       \n");
11911         MrBayesPrint ("                   only done to non-cold chains. The format for this parameter   \n");
11912         MrBayesPrint ("                   is \"reweight=(<number>,<number>)\" or \"reweight=(<number>,  \n");
11913         MrBayesPrint ("                   <number>,<number>)\".                                         \n");
11914         MrBayesPrint ("   Swapfreq     -- This specifies how often swaps of states between chains are   \n");
11915         MrBayesPrint ("                   attempted. You must be running at least two chains for this   \n");
11916         MrBayesPrint ("                   option to be relevant. The default is Swapfreq=1, resulting   \n");
11917         MrBayesPrint ("                   in Nswaps (see below) swaps being tried each generation of    \n");
11918         MrBayesPrint ("                   the run. If Swapfreq is set to 10, then Nswaps swaps will be  \n");
11919         MrBayesPrint ("                   tried every tenth generation of the run.                      \n");
11920         MrBayesPrint ("   Nswaps       -- The number of swaps tried for each swapping generation of the \n");
11921         MrBayesPrint ("                   chain (see also Swapfreq).                                    \n");
11922         MrBayesPrint ("   Samplefreq   -- This specifies how often the Markov chain is sampled. You     \n");
11923         MrBayesPrint ("                   can sample the chain every cycle, but this results in very    \n");
11924         MrBayesPrint ("                   large output files. Thinning the chain is a way of making     \n");
11925         MrBayesPrint ("                   these files smaller and making the samples more independent.  \n");
11926         MrBayesPrint ("   Printfreq    -- This specifies how often information about the chain is       \n");
11927         MrBayesPrint ("                   printed to the screen.                                        \n");
11928         MrBayesPrint ("   Printall     -- If set to NO, only cold chains in a MCMC analysis are printed \n");
11929         MrBayesPrint ("                   to screen. If set to YES, both cold and heated chains will be \n");
11930         MrBayesPrint ("                   output. This setting only affects the printing to screen, it  \n");
11931         MrBayesPrint ("                   does not change the way values are written to file.           \n");
11932         MrBayesPrint ("   Printmax     -- The maximum number of chains to print to screen.              \n");
11933         MrBayesPrint ("   Mcmcdiagn    -- Determines whether acceptance ratios of moves and swaps will  \n");
11934         MrBayesPrint ("                   be printed to file. The file will be named similarly to the   \n");
11935         MrBayesPrint ("                   '.p' and '.t' files, but will have the ending '.mcmc'. If     \n");
11936         MrBayesPrint ("                   more than one independent analysis is run simultaneously (see \n");
11937         MrBayesPrint ("                   Nruns below), convergence diagnostics for tree topology will  \n");
11938         MrBayesPrint ("                   also be printed to this file. The convergence diagnostic used \n");
11939         MrBayesPrint ("                   is the average standard deviation in partition frequency      \n");
11940         MrBayesPrint ("                   values across independent analyses. The Burnin setting (see   \n");
11941         MrBayesPrint ("                   below) determines how many samples will be discarded as burnin\n");
11942         MrBayesPrint ("                   before calculating the partition frequencies. The Minpartfreq \n");
11943         MrBayesPrint ("                   setting (see below) determines the minimum partition frequency\n");
11944         MrBayesPrint ("                   required for a partition to be included in the calculation. As\n");
11945         MrBayesPrint ("                   the independent analyses approach stationarity (converge), the\n");
11946         MrBayesPrint ("                   value of the diagnostic is expected to approach zero.         \n");
11947         MrBayesPrint ("   Diagnfreq    -- The number of generations between the calculation of MCMC     \n");
11948         MrBayesPrint ("                   diagnostics (see Mcmcdiagn above).                            \n");
11949         MrBayesPrint ("   Diagnstat    -- The statistic to use for run-time convergence diagnostics.    \n");
11950         MrBayesPrint ("                   Choices are 'Avgstddev' for average standard deviation of     \n");
11951         MrBayesPrint ("                   split frequencies and 'Maxstddev' for maximum standard devia- \n");
11952         MrBayesPrint ("                   tion of split frequencies.                                    \n");
11953         MrBayesPrint ("   Savetrees    -- If you are using a relative burnin for run-time convergence   \n");
11954         MrBayesPrint ("                   diagnostics, tree samples need to be deleted from split       \n");
11955         MrBayesPrint ("                   frequency counters as the cut-off point for the burnin moves  \n");
11956         MrBayesPrint ("                   during the run. If 'Savetrees' is set to 'No', tree samples   \n");
11957         MrBayesPrint ("                   to be discarded are read back in from file. If 'Savetrees' is \n");
11958         MrBayesPrint ("                   set to 'Yes', the tree samples to be removed will be stored   \n");
11959         MrBayesPrint ("                   in the internal memory instead. This can use up a lot of      \n");
11960         MrBayesPrint ("                   memory in large analyses.                                     \n");
11961         MrBayesPrint ("   Minpartfreq  -- The minimum frequency required for a partition to be included \n");
11962         MrBayesPrint ("                   in the calculation of the topology convergence diagnostic. The\n");
11963         MrBayesPrint ("                   partition is included if the minimum frequency is reached in  \n");
11964         MrBayesPrint ("                   at least one of the independent tree samples that are com-    \n");
11965         MrBayesPrint ("                   pared.                                                        \n");
11966         MrBayesPrint ("   Allchains    -- If this option is set to YES, acceptance ratios for moves are \n");
11967         MrBayesPrint ("                   recorded for all chains, cold or heated. By default, only the \n");
11968         MrBayesPrint ("                   acceptance ratios for the cold chain are recorded.            \n");
11969         MrBayesPrint ("   Allcomps     -- If this option is set to YES, topological convergence diag-   \n");
11970         MrBayesPrint ("                   nostics are calculated over all pairwise comparisons of runs. \n");
11971         MrBayesPrint ("                   If it is set to NO, only the overall value is reported.       \n");
11972         MrBayesPrint ("   Relburnin    -- If this option is set to YES, then a proportion of the sampled\n");
11973         MrBayesPrint ("                   values will be discarded as burnin when calculating the con-  \n");
11974         MrBayesPrint ("                   vergence diagnostic. The proportion to be discarded is set    \n");
11975         MrBayesPrint ("                   with Burninfrac (see below). When the Relburnin option is set \n");
11976         MrBayesPrint ("                   to NO, then a specific number of samples will be discarded    \n");
11977         MrBayesPrint ("                   instead. This number is set by Burnin (see below).            \n");
11978         MrBayesPrint ("   Burnin       -- Determines the number of samples (not generations) that will  \n");
11979         MrBayesPrint ("                   be discarded when convergence diagnostics are calculated.     \n");
11980         MrBayesPrint ("                   The value of this option is only relevant when Relburnin is   \n");
11981         MrBayesPrint ("                   set to NO.                                                    \n");
11982         MrBayesPrint ("   BurninFrac   -- Determines the fraction of samples that will be discarded     \n");
11983         MrBayesPrint ("                   when convergence diagnostics are calculated. The value of     \n");
11984         MrBayesPrint ("                   this option is only relevant when Relburnin is set to YES.    \n");
11985         MrBayesPrint ("                   Example: A value for this option of 0.25 means that 25%% of   \n");
11986         MrBayesPrint ("                   the samples will be discarded.                                \n");
11987         MrBayesPrint ("   Stoprule     -- If this option is set to NO, then the chain is run the number \n");
11988         MrBayesPrint ("                   of generations determined by Ngen. If it is set to YES, and   \n");
11989         MrBayesPrint ("                   topological convergence diagnostics are calculated (Mcmcdiagn \n");
11990         MrBayesPrint ("                   is set to YES), then the chain will be stopped before the pre-\n");
11991         MrBayesPrint ("                   determined number of generations if the convergence diagnostic\n");
11992         MrBayesPrint ("                   falls below the stop value.                                   \n");
11993         MrBayesPrint ("   Stopval      -- The critical value for the topological convergence diagnostic.\n");
11994         MrBayesPrint ("                   Only used when Stoprule and Mcmcdiagn are set to yes, and     \n");
11995         MrBayesPrint ("                   more than one analysis is run simultaneously (Nruns > 1).     \n");
11996         MrBayesPrint ("   Checkpoint   -- If this parameter is set to 'Yes', all the current parameter  \n");
11997         MrBayesPrint ("                   values of all chains will be printed to a check-pointing file \n");
11998         MrBayesPrint ("                   every 'Checkfreq' generation of the analysis. The file will be\n");
11999         MrBayesPrint ("                   named <Filename>.ckp and allows you to restart the analysis   \n");
12000         MrBayesPrint ("                   from the last check point. This can be handy if you are       \n");
12001         MrBayesPrint ("                   running a long analysis and want to extend it, or if there is \n");
12002         MrBayesPrint ("                   a risk that a long analysis will be inadvertently interrupted \n");
12003         MrBayesPrint ("                   by hardware failure or other factors that are out of your     \n");
12004         MrBayesPrint ("                   control.                                                      \n");
12005         MrBayesPrint ("   Checkfreq    -- The number of generations between check-pointing. See the     \n");
12006         MrBayesPrint ("                   'Checkpoint' parameter above for more information.            \n");
12007         MrBayesPrint ("   Filename     -- The name of the files that will be generated. Two files       \n");
12008         MrBayesPrint ("                   are generated: \"<Filename>.t\" and \"<Filename>.p\".         \n");
12009         MrBayesPrint ("                   The .t file contains the trees whereas the .p file con-       \n");
12010         MrBayesPrint ("                   tains the sampled values of the parameters.                   \n");
12011         MrBayesPrint ("   Startparams  -- The starting values for the model parameters are set to       \n");
12012         MrBayesPrint ("                   arbitrary or random values when the parameters are created.   \n");
12013         MrBayesPrint ("                   These starting values can be altered using the 'Startvals'    \n");
12014         MrBayesPrint ("                   command. The 'Startparams=reset' option allows you to reset   \n");
12015         MrBayesPrint ("                   the starting values to the default at the start of the ana-   \n");
12016         MrBayesPrint ("                   lysis, overriding any previous user-defined starting values.  \n");
12017         MrBayesPrint ("                   Under the default option, 'current', the chains will use the  \n");
12018         MrBayesPrint ("                   current starting values.                                      \n");
12019         MrBayesPrint ("   Starttree    -- The starting tree(s) for the chain can either be randomly     \n");
12020         MrBayesPrint ("                   selected or user-defined. It might be a good idea to          \n");
12021         MrBayesPrint ("                   start from randomly chosen trees; convergence seems           \n");
12022         MrBayesPrint ("                   likely if independently run chains, each of which             \n");
12023         MrBayesPrint ("                   started from different random trees, converge to the same     \n");
12024         MrBayesPrint ("                   answer. If you want the chain to start from user-defined      \n");
12025         MrBayesPrint ("                   trees instead, you first need to read in your tree(s) from a  \n");
12026         MrBayesPrint ("                   Nexus file with a 'trees' block, and then you need to set the \n");
12027         MrBayesPrint ("                   starting tree(s) using the 'Startvals' command. Finally, you  \n");
12028         MrBayesPrint ("                   need to make sure that 'Starttree' is set to 'current'. If    \n");
12029         MrBayesPrint ("                   you do not set the starting tree(s), the chains will start    \n");
12030         MrBayesPrint ("                   with random trees. Setting 'Starttree' to 'random' causes     \n");
12031         MrBayesPrint ("                   new starting trees to be drawn randomly at the start of the   \n");
12032         MrBayesPrint ("                   run, overwriting any previous user-defined starting trees.    \n");
12033         MrBayesPrint ("   Nperts       -- This is the number of random perturbations to apply to the    \n");
12034         MrBayesPrint ("                   user starting tree. This allows you to have something         \n");
12035         MrBayesPrint ("                   between completely random and user-defined trees start        \n");
12036         MrBayesPrint ("                   the chain.                                                    \n");
12037         MrBayesPrint ("   Data         -- When Data is set to NO, the chain is run without data. This   \n");
12038         MrBayesPrint ("                   should be used only for examining induced priors. DO NOT SET  \n");
12039         MrBayesPrint ("                   'DATA' TO 'NO' UNLESS YOU KNOW WHAT YOU ARE DOING!            \n");
12040         MrBayesPrint ("   Ordertaxa    -- Determines whether taxa should be ordered before trees are    \n");
12041         MrBayesPrint ("                   printed to file. If set to 'Yes', terminals in the sampled    \n");
12042         MrBayesPrint ("                   trees will be reordered to match the order of the taxa in the \n");
12043         MrBayesPrint ("                   data matrix as closely as possible. By default, trees will be \n");
12044         MrBayesPrint ("                   printed without reordering of taxa.                           \n");
12045         MrBayesPrint ("   Append       -- Set this to 'Yes' to append the results of the current run to \n");
12046         MrBayesPrint ("                   a previous run. MrBayes will first read in the results of the \n");
12047         MrBayesPrint ("                   previous run (number of generations and sampled splits) and   \n");
12048         MrBayesPrint ("                   will then continue that run where you left it off. Make sure  \n");
12049         MrBayesPrint ("                   that the output file names used in the previous run are the   \n");
12050         MrBayesPrint ("                   same as those in the current run.                             \n");
12051         MrBayesPrint ("   Autotune     -- Set this to 'Yes' to autotune the proposals that change       \n");
12052         MrBayesPrint ("                   substitution model parameters. When set to 'No', the tuning   \n");
12053         MrBayesPrint ("                   parameters are fixed to their starting values. Note that the  \n");
12054         MrBayesPrint ("                   autotuning occurs independently for each chain. The target    \n");
12055         MrBayesPrint ("                   acceptance rate for each move can be changed using the        \n");
12056         MrBayesPrint ("                   'Propset' command.                                            \n");
12057         MrBayesPrint ("   Tunefreq     -- When a proposal has been tried 'Tunefreq' times, its tuning   \n");
12058         MrBayesPrint ("                   parameter is adjusted to reach the target acceptance rate     \n");
12059         MrBayesPrint ("                   if 'Autotune' is set to 'Yes'.                                \n");
12060         MrBayesPrint ("                                                                                 \n");
12061         PrintSettings ("Mcmc");
12062         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12063         }
12064     else if (!strcmp(helpTkn, "Mcmcp"))
12065         {
12066         // PrintYesNo (chainParams.saveBrlens, yesNoStr);
12067         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12068         MrBayesPrint ("   Mcmcp                                                                         \n");
12069         MrBayesPrint ("                                                                                 \n");
12070         MrBayesPrint ("   This command sets the parameters of the Markov chain Monte Carlo (MCMC)       \n");
12071         MrBayesPrint ("   analysis without actually starting the chain. This command is identical       \n");
12072         MrBayesPrint ("   in all respects to Mcmc, except that the analysis will not start after        \n");
12073         MrBayesPrint ("   this command is issued. For more details on the options, check the help       \n");
12074         MrBayesPrint ("   menu for Mcmc.\n");
12075         MrBayesPrint ("                                                                                 \n");
12076         PrintSettings ("Mcmc");
12077         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12078         }
12079     else if (!strcmp(helpTkn, "Ss"))
12080         {
12081         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12082         MrBayesPrint ("   Ss                                                                            \n");
12083         MrBayesPrint ("                                                                                 \n");
12084         MrBayesPrint ("   This command is used to start stepping-stone sampling, which is an efficient  \n");
12085         MrBayesPrint ("   and accurate method for estimating the marginal likelihood of the currently   \n");
12086         MrBayesPrint ("   specified model. It is considerably more accurate than the harmonic mean of   \n");
12087         MrBayesPrint ("   the likelihoods from a standard MCMC run on the model (calculated by the      \n");
12088         MrBayesPrint ("   'Sump' command) but it requires a separate MCMC-like run. To be more specific,\n");
12089         MrBayesPrint ("   stepping-stone sampling uses importance sampling to estimate each ratio in a  \n");
12090         MrBayesPrint ("   series of discrete steps bridging the posterior and prior distributions.      \n");
12091         MrBayesPrint ("   The importance distributions that are used are called power posterior distri- \n");
12092         MrBayesPrint ("   butions, and are defined as prior*(likelihood^beta). By varying beta from 1 to\n");
12093         MrBayesPrint ("   0, we get a series of distributions that connect the posterior (beta = 1) to  \n");
12094         MrBayesPrint ("   the prior (beta = 0).                                                         \n");
12095         MrBayesPrint ("                                                                                 \n");
12096         MrBayesPrint ("   The power posterior distributions are sampled using MCMC. First, we start a   \n");
12097         MrBayesPrint ("   standard MCMC chain on the posterior distribution, and let it run until we    \n");
12098         MrBayesPrint ("   have reached the criterion specified by the 'Burninss' option. After this, we \n");
12099         MrBayesPrint ("   step through the power posterior distributions until we reach the prior dis-  \n");
12100         MrBayesPrint ("   tribution. In each of the 'Nsteps' steps, we sample from a new power poster-  \n");
12101         MrBayesPrint ("   ior distribution with a distinct beta value. The beta values correspond to    \n");
12102         MrBayesPrint ("   'Nsteps' evenly spaced quantiles in a Beta distribution with the parameters   \n");
12103         MrBayesPrint ("   'Alpha' and 1.0. For the first sampling step, the beta value is equal to the  \n");
12104         MrBayesPrint ("   last quantile, i.e., it is close to 1.0. For each successive step, the beta   \n");
12105         MrBayesPrint ("   value takes on the value of the next quantile, in decreasing order, until it  \n");
12106         MrBayesPrint ("   reaches the value of 0.0. If you change value of 'FromPrior' from default 'No'\n");
12107         MrBayesPrint ("   to 'Yes' then the direction of power posterior change during SS analizes is   \n");
12108         MrBayesPrint ("   opposite to the one described above, i.e. we start from sampling prior and    \n");
12109         MrBayesPrint ("   finish close to posterior.                                                    \n");
12110         MrBayesPrint ("                                                                                 \n");
12111         MrBayesPrint ("   The 'Ss' procedure uses the same machinery as the standard 'Mcmc' algorithm,  \n");
12112         MrBayesPrint ("   and shares most of its parameters with the 'Mcmc' and 'Mcmcp' commands. All   \n");
12113         MrBayesPrint ("   'Mcmc' parameters, except those related to burnin, have the same meaning and  \n");
12114         MrBayesPrint ("   usage in the 'Ss' command as they have in the 'Mcmc' command. The 'Mcmc'      \n");
12115         MrBayesPrint ("   burnin parameters are used to set up burnin within each step. The 'Ss' command\n");
12116         MrBayesPrint ("   also uses its own burnin parameter, 'Burninss' (see below for details). The   \n");
12117         MrBayesPrint ("   'Ss' command also has its own parameters for specifying the number of steps   \n");
12118         MrBayesPrint ("   and the shape of the Beta distribution from which the beta values are computed\n");
12119         MrBayesPrint ("   (see below).                                                                  \n");
12120         MrBayesPrint ("                                                                                 \n");
12121         MrBayesPrint ("   Note that the 'Ngen' parameter of 'Mcmc' is used to set the maximum number of \n");
12122         MrBayesPrint ("   generations processed, including both the burnin and the following steps in   \n");
12123         MrBayesPrint ("   the stepping-stone sampling phase. For instance, assume that 'Burninss' is set\n");
12124         MrBayesPrint ("   to '-1', 'Nsteps' to '49', 'Ngen' to '1000000' and 'Samplefreq' to '1000'.    \n");
12125         MrBayesPrint ("   We will then get 1,000 samples in total (1,000,000 / 1,000). These will fall  \n");
12126         MrBayesPrint ("   into 50 bins, one of which represents the burnin and is discarded. Each step  \n");
12127         MrBayesPrint ("   in the algorithm will thus be represented by 20 samples.                      \n");
12128         MrBayesPrint ("                                                                                 \n");
12129         MrBayesPrint ("   More information on 'Mcmc' parameters is available in the help for the 'Mcmc' \n");
12130         MrBayesPrint ("   and 'Mcmcp' commands. Only the exclusive 'Ss' parameters are listed below.    \n");
12131         MrBayesPrint ("   These can only be set up using the 'Ss' command, while the parameters shared  \n");
12132         MrBayesPrint ("   with 'Mcmc' and 'Mcmcp' can also be set up using those commands.              \n");
12133         MrBayesPrint ("                                                                                 \n");
12134         MrBayesPrint ("   The correct usage is                                                          \n");
12135         MrBayesPrint ("                                                                                 \n");
12136         MrBayesPrint ("      ss <parameter>=<value> ... <parameter>=<value>                             \n");
12137         MrBayesPrint ("                                                                                 \n");
12138         MrBayesPrint ("   Note that a command:                                                          \n");
12139         MrBayesPrint ("                                                                                 \n");
12140         MrBayesPrint ("      ss <setting parameters shared with mcmc> <setting exclusive ss parameters> \n");
12141         MrBayesPrint ("                                                                                 \n");
12142         MrBayesPrint ("   would be equivalent to executing two commands:                                \n");
12143         MrBayesPrint ("                                                                                 \n");
12144         MrBayesPrint ("     mcmcp <setting parameters shared with mcmc>;                                \n");
12145         MrBayesPrint ("     ss <setting exclusive ss parameters>;                                       \n");
12146         MrBayesPrint ("                                                                                 \n");
12147         MrBayesPrint ("   For more information on the stepping-stone algorithm, see:                    \n");
12148         MrBayesPrint ("                                                                                 \n");
12149         MrBayesPrint ("   Xie, W., P. O. Lewis, Y. Fan, L. Kuo, and M.-H. Chen. 2011. Improving marginal\n");
12150         MrBayesPrint ("      likelihood estimation for Bayesian phylogenetic model selection. Systematic\n");
12151         MrBayesPrint ("      Biology 60:150-160.                                                        \n");
12152         MrBayesPrint ("                                                                                 \n");
12153         MrBayesPrint ("   Available options:                                                            \n");
12154         MrBayesPrint ("   (NB: Only exclusive ss parameters listed here. For additional parameters, see \n");
12155         MrBayesPrint ("        help on 'mcmc' or 'mcmcp'.                                               \n");
12156         MrBayesPrint ("                                                                                 \n");
12157         MrBayesPrint ("   Alpha        -- The beta values used in the stepping-stone sampling procedure \n");
12158         MrBayesPrint ("                   correspond to evenly spaced quantiles from a Beta('Alpha',1.0)\n");
12159         MrBayesPrint ("                   distribution. The parameter 'Alpha' determines the skewness of\n");
12160         MrBayesPrint ("                   the beta values. If 'Alpha' is set to '1.0', the beta values  \n");
12161         MrBayesPrint ("                   would be spaced uniformly on the interval (0.0,1.0). However, \n");
12162         MrBayesPrint ("                   better results are obtained if the beta values are skewed.    \n");
12163         MrBayesPrint ("                   Empirically, it was observed that 'Alpha' values in the range \n");
12164         MrBayesPrint ("                   of 0.3 to 0.5 produce the most accurate results.              \n");
12165         MrBayesPrint ("   Burninss     -- Fixed number of samples discarded before sampling of the first\n");
12166         MrBayesPrint ("                   step starts. 'Burninss' can be specified using either a pos-  \n");
12167         MrBayesPrint ("                   itive or a negative number. If the number is positive, it is  \n");
12168         MrBayesPrint ("                   interpreted as the number of samples to discard as burnin. If \n");
12169         MrBayesPrint ("                   the number is negative, its absolute value is interpreted as  \n");
12170         MrBayesPrint ("                   the length of the burnin in terms of the length of each of the\n");
12171         MrBayesPrint ("                   following steps in the stepping-stone algorithm. For instance,\n");
12172         MrBayesPrint ("                   a value of '-1' means that the length of the burnin is the    \n");
12173         MrBayesPrint ("                   same as the length of each of the subsequent steps.           \n");
12174         MrBayesPrint ("   Nsteps       -- Number of steps in the stepping-stone algorithm. Typically, a \n");
12175         MrBayesPrint ("                   number above 30 is sufficient for accurate results.           \n");
12176         MrBayesPrint ("   FromPrior    -- If it is set to 'Yes', it indicates that in the first step we \n");
12177         MrBayesPrint ("                   sample from the prior, with each consecutive step we sample   \n");
12178         MrBayesPrint ("                   closer to the posterior. 'No' indicates the opposite direction\n");
12179         MrBayesPrint ("                   of power posterior change, i.e. in the first step we sample   \n");
12180         MrBayesPrint ("                   close to the posterior, and with each consecutive step we     \n");
12181         MrBayesPrint ("                   sample closer to the prior.                                   \n");
12182         MrBayesPrint ("                                                                                 \n");
12183         MrBayesPrint ("   Current settings:                                                             \n");
12184         MrBayesPrint ("                                                                                 \n");
12185         MrBayesPrint ("   Parameter          Options               Current Setting                      \n");
12186         MrBayesPrint ("   --------------------------------------------------------                      \n");
12187         MrBayesPrint ("   Alpha              <number>              %1.2lf\n", chainParams.alphaSS);
12188         MrBayesPrint ("   BurninSS           <number>              %d\n", chainParams.burninSS);
12189         MrBayesPrint ("   Nsteps             <number>              %d\n", chainParams.numStepsSS);
12190         MrBayesPrint ("   FromPrior           Yes/No               %s                                   \n", chainParams.startFromPriorSS == YES ? "Yes" : "No");
12191         MrBayesPrint ("                                                                                 \n");
12192         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12193         }
12194 else if (!strcmp(helpTkn, "Ssp"))
12195         {
12196         // PrintYesNo (chainParams.saveBrlens, yesNoStr);
12197         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12198         MrBayesPrint ("   Ssp                                                                           \n");
12199         MrBayesPrint ("                                                                                 \n");
12200         MrBayesPrint ("   This command sets the parameters of the stepping-stone sampling               \n");
12201         MrBayesPrint ("   analysis without actually starting the chain. This command is identical       \n");
12202         MrBayesPrint ("   in all respects to Ss, except that the analysis will not start after          \n");
12203         MrBayesPrint ("   this command is issued. For more details on the options, check the help       \n");
12204         MrBayesPrint ("   menu for Ss.\n");
12205         MrBayesPrint ("                                                                                 \n");
12206         MrBayesPrint ("   Current settings:                                                             \n");
12207         MrBayesPrint ("                                                                                 \n");
12208         MrBayesPrint ("   Parameter          Options               Current Setting                      \n");
12209         MrBayesPrint ("   --------------------------------------------------------                      \n");
12210         MrBayesPrint ("   Alpha              <number>              %1.2lf\n", chainParams.alphaSS);
12211         MrBayesPrint ("   BurninSS           <number>              %d\n", chainParams.burninSS);
12212         MrBayesPrint ("   Nsteps             <number>              %d\n", chainParams.numStepsSS);
12213         MrBayesPrint ("   FromPrior           Yes/No               %s                                   \n", chainParams.startFromPriorSS == YES ? "Yes" : "No");
12214         MrBayesPrint ("                                                                                 \n");
12215         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12216         }
12217 else if (!strcmp(helpTkn, "Set"))
12218         {
12219         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12220         MrBayesPrint ("   Set                                                                           \n");
12221         MrBayesPrint ("                                                                                 \n");
12222         MrBayesPrint ("   This command is used to set some general features of the model or program     \n");
12223         MrBayesPrint ("   behavior. The correct usage is                                                \n");
12224         MrBayesPrint ("                                                                                 \n");
12225         MrBayesPrint ("      set <parameter>=<value> ... <parameter>=<value>                            \n");
12226         MrBayesPrint ("                                                                                 \n");
12227         MrBayesPrint ("   Available options:                                                            \n");
12228         MrBayesPrint ("                                                                                 \n");
12229         MrBayesPrint ("   Seed         -- Sets the seed number for the random number generator. The     \n");
12230         MrBayesPrint ("                   random number seed is initialized haphazardly at the beg-     \n");
12231         MrBayesPrint ("                   inning of each MrBayes session. This option allows you to     \n");
12232         MrBayesPrint ("                   set the seed to some specific value, thereby allowing you     \n");
12233         MrBayesPrint ("                   to exactly repeat an analysis. If the analysis uses swapping  \n");
12234         MrBayesPrint ("                   between cold and heated chains, you must also set the swap    \n");
12235         MrBayesPrint ("                   seed (see below) to exactly repeat the analysis.              \n");
12236         MrBayesPrint ("   Swapseed     -- Sets the seed used for generating the swapping sequence       \n");
12237         MrBayesPrint ("                   when Metropolis-coupled heated chains are used. This seed     \n");
12238         MrBayesPrint ("                   is initialized haphazardly at the beginning of each MrBayes   \n");
12239         MrBayesPrint ("                   session. This option allows you to set the seed to some       \n");
12240         MrBayesPrint ("                   specific value, thereby allowing you to exactly repeat a      \n");
12241         MrBayesPrint ("                   swap sequence. See also the 'Seed' option.                    \n");
12242         MrBayesPrint ("   Dir          -- The working directory. Specifies the absolute or relative path\n");
12243         MrBayesPrint ("                   to the working directory. If left empty, the working directory\n");
12244         MrBayesPrint ("                   is the current directory.                                     \n");
12245         MrBayesPrint ("   Partition    -- Set this option to a valid partition id, either the number or \n");
12246         MrBayesPrint ("                   name of a defined partition, to enforce a specific partition- \n");
12247         MrBayesPrint ("                   ing of the data. When a data matrix is read in, a partition   \n");
12248         MrBayesPrint ("                   called \"Default\" is automatically created. It divides the   \n");
12249         MrBayesPrint ("                   data into one part for each data type. If you only have one   \n");
12250         MrBayesPrint ("                   data type, DNA for instance, the default partition will not   \n");
12251         MrBayesPrint ("                   divide up the data at all. The default partition is always    \n");
12252         MrBayesPrint ("                   the first partition, so 'set partition=1' is the same as      \n");
12253         MrBayesPrint ("                   'set partition=default'.                                      \n");
12254         MrBayesPrint ("   Speciespartition -- Set this option to a valid speciespartition id, either the\n");
12255         MrBayesPrint ("                   number or name of a defined speciespartition, to enforce a    \n");
12256         MrBayesPrint ("                   specific partitioning of taxa to species. When a data matrix  \n");
12257         MrBayesPrint ("                   is read in, a speciespartition called \"Default\" is auto-    \n");
12258         MrBayesPrint ("                   matically created. It assigns one taxon for each species. The \n");
12259         MrBayesPrint ("                   default speciespartition is always the first speciespartition,\n");
12260         MrBayesPrint ("                   so 'set speciespartition=1' is the same as                    \n");
12261         MrBayesPrint ("                   'set speciespartition=default'.                               \n");
12262         MrBayesPrint ("   Autoclose    -- If autoclose is set to 'yes', then the program will not prompt\n");
12263         MrBayesPrint ("                   you during the course of executing a file. This is particular-\n");
12264         MrBayesPrint ("                   ly useful when you run MrBayes in batch mode.                 \n");
12265         MrBayesPrint ("   Nowarnings   -- If nowarnings is set to yes, then the program will not prompt \n");
12266         MrBayesPrint ("                   you when overwriting or appending an output file that is al-  \n");
12267         MrBayesPrint ("                   ready present. If 'nowarnings=no' (the default setting), then \n");
12268         MrBayesPrint ("                   the program propts the user before overwriting output files.  \n");
12269         MrBayesPrint ("   Autoreplace  -- When nowarnings is set to yes, then MrBayes will by default   \n");
12270         MrBayesPrint ("                   overwrite output files that already exists. This may cause    \n");
12271         MrBayesPrint ("                   irrecoverable loss of previous results if you have not removed\n");
12272         MrBayesPrint ("                   or renamed the files from previous runs. To override this be- \n");
12273         MrBayesPrint ("                   havior, set autoreplace to no, in which case new output will  \n");
12274         MrBayesPrint ("                   be appended to existing files instead.                        \n");
12275         MrBayesPrint ("   Quitonerror  -- If quitonerror is set to yes, then the program will quit when \n");
12276         MrBayesPrint ("                   an error is encountered, after printing an error message. If  \n");
12277         MrBayesPrint ("                   quitonerror is set to no (the default setting), then the      \n");
12278         MrBayesPrint ("                   program will wait for additional commands from the command    \n");
12279         MrBayesPrint ("                   line after the error message is printed.                      \n");
12280         MrBayesPrint ("   Scientific   -- Set this option to 'Yes' to write sampled values to file in   \n");
12281         MrBayesPrint ("                   scientific format and to 'No' to write them in fixed format.  \n");
12282         MrBayesPrint ("                   Fixed format is easier for humans to read but you risk losing \n");
12283         MrBayesPrint ("                   precision for small numbers. For instance, sampled values that\n");
12284         MrBayesPrint ("                   are less than 1E-6 will print to file as '0.000000' if fixed  \n");
12285         MrBayesPrint ("                   format is used and 'precision' is set to 6.                   \n");
12286         MrBayesPrint ("   Precision    -- Precision allows you to set the number of decimals to be prin-\n");
12287         MrBayesPrint ("                   ted when sampled values are written to file. Precision must be\n");
12288         MrBayesPrint ("                   in the range 3 to 15.                                         \n");
12289 #   if defined (BEAGLE_ENABLED)
12290         MrBayesPrint ("   Usebeagle    -- Set this option to 'Yes' to attempt to use the BEAGLE library \n");
12291         MrBayesPrint ("                   to compute the phylogenetic likelihood on a variety of high-  \n");
12292         MrBayesPrint ("                   performance hardware including multicore CPUs and GPUs. Some  \n");
12293         MrBayesPrint ("                   models in MrBayes are not yet supported by BEAGLE.            \n");
12294         MrBayesPrint ("   Beagleresource -- Set this option to the number of a specific resource you    \n");
12295         MrBayesPrint ("                   wish to use with BEAGLE (use 'Showbeagle' to see the list of  \n");
12296         MrBayesPrint ("                   available resources). Set to '99' for auto-resource selection.\n");
12297         MrBayesPrint ("   Beagledevice -- Set this option to 'GPU' or 'CPU' to select processor.        \n");
12298         MrBayesPrint ("   Beagleprecision -- Selection 'Single' or 'Double' precision computation.      \n");
12299         MrBayesPrint ("   Beaglescaling -- 'Always' rescales partial likelihoods at each evaluation.    \n");
12300         MrBayesPrint ("                   'Dynamic' rescales less frequently and should run faster.     \n");
12301         MrBayesPrint ("   Beaglesse    -- Use SSE instructions on Intel CPU processors.                 \n");
12302 #   if defined (BEAGLE_V3_ENABLED)
12303         MrBayesPrint ("   Beaglethreads -- Use threading for parallelism on multi-core CPU processors.  \n");
12304         MrBayesPrint ("   Beaglethreadcount -- Set maximum number of CPU threads to be used by BEAGLE.  \n");
12305         MrBayesPrint ("                   Set to '99' for auto-threading.                               \n");
12306         MrBayesPrint ("   Beaglefloattips -- Use floating-point representation for tip sequence data.   \n");
12307         MrBayesPrint ("                   Can result in improved performance on GPU devices at the cost \n");
12308         MrBayesPrint ("                   of additional memory usage.                                   \n");
12309 #   endif
12310 #   endif
12311         MrBayesPrint ("                                                                                 \n");
12312         MrBayesPrint ("   Current settings:                                                             \n");
12313         MrBayesPrint ("                                                                                 \n");
12314         MrBayesPrint ("   Parameter          Options               Current Setting                      \n");
12315         MrBayesPrint ("   --------------------------------------------------------                      \n");
12316         MrBayesPrint ("   Seed               <number>              %ld                                  \n", globalSeed);
12317         MrBayesPrint ("   Swapseed           <number>              %ld                                  \n", swapSeed);
12318         MrBayesPrint ("   Dir                <name>                \"%s\"\n", workingDir);
12319         if (defMatrix == YES)
12320             MrBayesPrint ("   Partition          <name>                %s\n", partitionNames[partitionNum]);
12321         else
12322             MrBayesPrint ("   Partition          <name>                \"\"\n");
12323         if (defTaxa == YES)
12324             MrBayesPrint ("   Speciespartition   <name>                %s\n", speciespartitionNames[speciespartitionNum]);
12325         else
12326             MrBayesPrint ("   Speciespartition   <name>                \"\"\n");
12327         MrBayesPrint ("   Autoclose          Yes/No                %s                                   \n", autoClose == YES ? "Yes" : "No");
12328         MrBayesPrint ("   Nowarnings         Yes/No                %s                                   \n", noWarn == YES ? "Yes" : "No");
12329         MrBayesPrint ("   Autoreplace        Yes/No                %s                                   \n", autoOverwrite == YES ? "Yes" : "No");
12330         MrBayesPrint ("   Quitonerror        Yes/No                %s                                   \n", quitOnError == YES ? "Yes" : "No");
12331         MrBayesPrint ("   Scientific         Yes/No                %s                                   \n", scientific == YES ? "Yes" : "No");
12332         MrBayesPrint ("   Precision          <number>              %d                                   \n", precision);
12333 #   if defined (BEAGLE_ENABLED)
12334         MrBayesPrint ("   Usebeagle          Yes/No                %s                                   \n", tryToUseBEAGLE == YES ? "Yes" : "No");
12335         MrBayesPrint ("   Beagleresource     <number>              %d                                   \n", beagleResourceNumber);
12336         MrBayesPrint ("   Beagledevice       CPU/GPU               %s                                   \n", beagleFlags & BEAGLE_FLAG_PROCESSOR_GPU ? "GPU" : "CPU");
12337         MrBayesPrint ("   Beagleprecision    Single/Double         %s                                   \n", beagleFlags & BEAGLE_FLAG_PRECISION_SINGLE ? "Single" : "Double");
12338         MrBayesPrint ("   Beaglescaling      Always/Dynamic        %s                                   \n", beagleScalingScheme == MB_BEAGLE_SCALE_ALWAYS ? "Always" : "Dynamic");
12339         MrBayesPrint ("   Beaglesse          Yes/No                %s                                   \n", beagleFlags & BEAGLE_FLAG_VECTOR_SSE ? "Yes" : "No");
12340 #   if defined (BEAGLE_V3_ENABLED)
12341         MrBayesPrint ("   Beaglethreads      Yes/No                %s                                   \n", beagleFlags & BEAGLE_FLAG_THREADING_CPP ? "Yes" : "No");
12342         MrBayesPrint ("   Beaglethreadcount  <number>              %d                                   \n", beagleThreadCount);
12343         MrBayesPrint ("   Beaglefloattips    Yes/No                %s                                   \n", beagleAllFloatTips ? "Yes" : "No");
12344 #   endif
12345 #   endif
12346         MrBayesPrint ("                                                                                 \n");
12347         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12348         }
12349     else if (!strcmp(helpTkn, "Charset"))
12350         {
12351         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12352         MrBayesPrint ("   Charset                                                                       \n");
12353         MrBayesPrint ("                                                                                 \n");
12354         MrBayesPrint ("   This command defines a character set. The format for the charset command      \n");
12355         MrBayesPrint ("   is                                                                            \n");
12356         MrBayesPrint ("                                                                                 \n");
12357         MrBayesPrint ("      charset <name> = <character numbers>                                       \n");
12358         MrBayesPrint ("                                                                                 \n");
12359         MrBayesPrint ("   For example, \"charset first_pos = 1-720\\3\" defines a character set         \n");
12360         MrBayesPrint ("   called \"first_pos\" that includes every third site from 1 to 720.            \n");
12361         MrBayesPrint ("   The character set name cannot have any spaces in it. The slash (\\)           \n");
12362         MrBayesPrint ("   is a nifty way of telling the program to assign every third (or               \n");
12363         MrBayesPrint ("   second, or fifth, or whatever) character to the character set.                \n");
12364         MrBayesPrint ("   This option is best used not from the command line, but rather as a           \n");
12365         MrBayesPrint ("   line in the mrbayes block of a file. Note that you can use \".\" to           \n");
12366         MrBayesPrint ("   stand in for the last character (e.g., charset 1-.\\3).                       \n");
12367         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12368         }
12369     else if (!strcmp(helpTkn, "Outgroup"))
12370         {
12371         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12372         MrBayesPrint ("   Outgroup                                                                      \n");
12373         MrBayesPrint ("                                                                                 \n");
12374         MrBayesPrint ("   This command assigns a taxon to the outgroup. The correct usage is:           \n");
12375         MrBayesPrint ("                                                                                 \n");
12376         MrBayesPrint ("      outgroup <number>/<taxon name>                                             \n");
12377         MrBayesPrint ("                                                                                 \n");
12378         MrBayesPrint ("   For example, \"outgroup 3\" assigns the third taxon in the matrix to be       \n");
12379         MrBayesPrint ("   the outgroup. Similarly, \"outgroup Homo_sapiens\" assings the taxon          \n");
12380         MrBayesPrint ("   \"Homo_sapiens\" to be the outgroup (assuming that there is a taxon named     \n");
12381         MrBayesPrint ("   \"Homo_sapiens\" in the matrix). Only a single taxon can be assigned to       \n");
12382         MrBayesPrint ("   be the outgroup.                                                              \n");
12383         MrBayesPrint ("                                                                                 \n");
12384         if (defTaxa == YES)
12385             MrBayesPrint ("   Current outgroup: %s (taxon no. %d)\n", taxaNames[outGroupNum], outGroupNum+1);
12386         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12387         }
12388     else if (!strcmp(helpTkn, "Showusertrees"))
12389         {
12390         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12391         MrBayesPrint ("   Showusertrees                                                                 \n");
12392         MrBayesPrint ("                                                                                 \n");
12393         MrBayesPrint ("   This command shows the currently defined user trees. The correct usage        \n");
12394         MrBayesPrint ("   is \"showusertrees\".                                                         \n");
12395         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12396         }
12397     else if (!strcmp(helpTkn, "Showmcmctrees"))
12398         {
12399         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12400         MrBayesPrint ("   Showmcmctrees                                                                 \n");
12401         MrBayesPrint ("                                                                                 \n");
12402         MrBayesPrint ("   This command shows the current trees used by the Markov chains.               \n");
12403         MrBayesPrint ("   is \"showmcmctrees\".                                                         \n");
12404         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12405         }
12406     else if (!strcmp(helpTkn, "Deroot"))
12407         {
12408         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12409         MrBayesPrint ("   Deroot                                                                        \n");
12410         MrBayesPrint ("                                                                                 \n");
12411         MrBayesPrint ("   This command deroots the user tree. If the tree is already unrooted, a        \n");
12412         MrBayesPrint ("   warning is issued. The correct usage is \"deroot\".                           \n");
12413         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12414         }
12415     else if (!strcmp(helpTkn, "Root"))
12416         {
12417         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12418         MrBayesPrint ("   Root                                                                          \n");
12419         MrBayesPrint ("                                                                                 \n");
12420         MrBayesPrint ("   This command roots the tree. If the tree is already rooted, a warning         \n");
12421         MrBayesPrint ("   is issued. The tree is rooted at the midpoint between the outgroup species    \n");
12422         MrBayesPrint ("   and the ingroup species. The correct usage is \"root\".                       \n");
12423         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12424         }
12425     else if (!strcmp(helpTkn, "Taxset"))
12426         {
12427         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12428         MrBayesPrint ("   Taxset                                                                        \n");
12429         MrBayesPrint ("                                                                                 \n");
12430         MrBayesPrint ("   This command defines a taxon set. The format for the taxset command           \n");
12431         MrBayesPrint ("   is                                                                            \n");
12432         MrBayesPrint ("                                                                                 \n");
12433         MrBayesPrint ("      taxset <name> = <taxon names or numbers>                                   \n");
12434         MrBayesPrint ("                                                                                 \n");
12435         MrBayesPrint ("   For example, \"taxset apes = Homo Pan Gorilla Orang gibbon\" defines a        \n");
12436         MrBayesPrint ("   taxon set called \"apes\" that includes five taxa (namely, apes).             \n");
12437         MrBayesPrint ("   You can assign up to 30 taxon sets. This option is best used                  \n");
12438         MrBayesPrint ("   not from the command line but rather as a line in the mrbayes block           \n");
12439         MrBayesPrint ("   of a file.                                                                    \n");
12440         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12441         }
12442     else if (!strcmp(helpTkn, "Taxlabels"))
12443         {
12444         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12445         MrBayesPrint ("   Taxlabels                                                                     \n");
12446         MrBayesPrint ("                                                                                 \n");
12447         MrBayesPrint ("   This command defines taxon labels. It could be used within taxa block.        \n");
12448         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12449         }
12450     else if (!strcmp(helpTkn, "Charstat"))
12451         {
12452         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12453         MrBayesPrint ("   Charstat                                                                      \n");
12454         MrBayesPrint ("                                                                                 \n");
12455         MrBayesPrint ("   This command shows the status of all the characters. The correct usage        \n");
12456         MrBayesPrint ("   is                                                                            \n");
12457         MrBayesPrint ("                                                                                 \n");
12458         MrBayesPrint ("      charstat                                                                   \n");
12459         MrBayesPrint ("                                                                                 \n");
12460         MrBayesPrint ("   After typing \"charstat\", the character number, whether it is excluded       \n");
12461         MrBayesPrint ("   or included, and the partition identity are shown. The output is paused       \n");
12462         MrBayesPrint ("   every 100 characters. This pause can be turned off by setting autoclose       \n");
12463         MrBayesPrint ("   to \"yes\" (set autoclose=yes).                                               \n");
12464         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12465         }
12466     else if (!strcmp(helpTkn, "Taxastat"))
12467         {
12468         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12469         MrBayesPrint ("   Taxastat                                                                      \n");
12470         MrBayesPrint ("                                                                                 \n");
12471         MrBayesPrint ("   This command shows the status of all the taxa. The correct usage is           \n");
12472         MrBayesPrint ("                                                                                 \n");
12473         MrBayesPrint ("      taxastat                                                                   \n");
12474         MrBayesPrint ("                                                                                 \n");
12475         MrBayesPrint ("   After typing \"taxastat\", the taxon number, name, and whether it is          \n");
12476         MrBayesPrint ("   excluded or included are shown.                                               \n");
12477         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12478         }
12479     else if (!strcmp(helpTkn, "Partition"))
12480         {
12481         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12482         MrBayesPrint ("   Partition                                                                     \n");
12483         MrBayesPrint ("                                                                                 \n");
12484         MrBayesPrint ("   This command allows you to specify a character partition. The format for      \n");
12485         MrBayesPrint ("   this command is                                                               \n");
12486         MrBayesPrint ("                                                                                 \n");
12487         MrBayesPrint ("      partition <name> = <num parts>:<chars in first>, ...,<chars in last>       \n");
12488         MrBayesPrint ("                                                                                 \n");
12489         MrBayesPrint ("   For example, \"partition by_codon = 3:1st_pos,2nd_pos,3rd_pos\" specifies     \n");
12490         MrBayesPrint ("   a partition called \"by_codon\" which consists of three parts (first,         \n");
12491         MrBayesPrint ("   second, and third codon positions). Here, we are assuming that the sites      \n");
12492         MrBayesPrint ("   in each partition were defined using the charset command. You can specify     \n");
12493         MrBayesPrint ("   a partition without using charset as follows:                                 \n");
12494         MrBayesPrint ("                                                                                 \n");
12495         MrBayesPrint ("      partition by_codon = 3:1 4 6 9 12,2 5 7 10 13,3 6 8 11 14                  \n");
12496         MrBayesPrint ("                                                                                 \n");
12497         MrBayesPrint ("   However, we recommend that you use the charsets to define a set of char-      \n");
12498         MrBayesPrint ("   acters and then use these predefined sets when defining the partition.        \n");
12499         MrBayesPrint ("   Also, it makes more sense to define a partition as a line in the mrbayes      \n");
12500         MrBayesPrint ("   block than to issue the command from the command line (then again, you        \n");
12501         MrBayesPrint ("   may be a masochist, and want to do extra work).                               \n");
12502         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12503         }
12504     else if (!strcmp(helpTkn, "Exclude"))
12505         {
12506         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12507         MrBayesPrint ("   Exclude                                                                       \n");
12508         MrBayesPrint ("                                                                                 \n");
12509         MrBayesPrint ("   This command excludes characters from the analysis. The correct usage is      \n");
12510         MrBayesPrint ("                                                                                 \n");
12511         MrBayesPrint ("      exclude <number> <number> <number>                                         \n");
12512         MrBayesPrint ("                                                                                 \n");
12513         MrBayesPrint ("   or                                                                            \n");
12514         MrBayesPrint ("                                                                                 \n");
12515         MrBayesPrint ("      exclude <number> - <number>                                                \n");
12516         MrBayesPrint ("                                                                                 \n");
12517         MrBayesPrint ("   or                                                                            \n");
12518         MrBayesPrint ("                                                                                 \n");
12519         MrBayesPrint ("      exclude <charset>                                                          \n");
12520         MrBayesPrint ("                                                                                 \n");
12521         MrBayesPrint ("   or some combination thereof. Moreover, you can use the specifier \"\\\" to    \n");
12522         MrBayesPrint ("   exclude every nth character. For example, the following                       \n");
12523         MrBayesPrint ("                                                                                 \n");
12524         MrBayesPrint ("      exclude 1-100\\3                                                           \n");
12525         MrBayesPrint ("                                                                                 \n");
12526         MrBayesPrint ("   would exclude every third character. As a specific example,                   \n");
12527         MrBayesPrint ("                                                                                 \n");
12528         MrBayesPrint ("      exclude 2 3 10-14 22                                                       \n");
12529         MrBayesPrint ("                                                                                 \n");
12530         MrBayesPrint ("   excludes sites 2, 3, 10, 11, 12, 13, 14, and 22 from the analysis. Also,      \n");
12531         MrBayesPrint ("                                                                                 \n");
12532         MrBayesPrint ("      exclude all                                                                \n");
12533         MrBayesPrint ("                                                                                 \n");
12534         MrBayesPrint ("   excludes all of the characters from the analysis. Excluding all characters    \n");
12535         MrBayesPrint ("   does not leave you much information for inferring phylogeny.                  \n");
12536         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12537         }
12538     else if (!strcmp(helpTkn, "Include"))
12539         {
12540         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12541         MrBayesPrint ("   Include                                                                       \n");
12542         MrBayesPrint ("                                                                                 \n");
12543         MrBayesPrint ("   This command includes characters that were previously excluded from the       \n");
12544         MrBayesPrint ("   analysis. The correct usage is                                                \n");
12545         MrBayesPrint ("                                                                                 \n");
12546         MrBayesPrint ("      include <number> <number> <number>                                         \n");
12547         MrBayesPrint ("                                                                                 \n");
12548         MrBayesPrint ("   or                                                                            \n");
12549         MrBayesPrint ("                                                                                 \n");
12550         MrBayesPrint ("      include <number> - <number>                                                \n");
12551         MrBayesPrint ("                                                                                 \n");
12552         MrBayesPrint ("   or                                                                            \n");
12553         MrBayesPrint ("                                                                                 \n");
12554         MrBayesPrint ("      include <charset>                                                          \n");
12555         MrBayesPrint ("                                                                                 \n");
12556         MrBayesPrint ("   or some combination thereof. Moreover, you can use the specifier \"\\\" to    \n");
12557         MrBayesPrint ("   include every nth character. For example, the following                       \n");
12558         MrBayesPrint ("                                                                                 \n");
12559         MrBayesPrint ("      include 1-100\\3                                                           \n");
12560         MrBayesPrint ("                                                                                 \n");
12561         MrBayesPrint ("   would include every third character. As a specific example,                   \n");
12562         MrBayesPrint ("                                                                                 \n");
12563         MrBayesPrint ("      include 2 3 10-14 22                                                       \n");
12564         MrBayesPrint ("                                                                                 \n");
12565         MrBayesPrint ("   includes sites 2, 3, 10, 11, 12, 13, 14, and 22 from the analysis. Also,      \n");
12566         MrBayesPrint ("                                                                                 \n");
12567         MrBayesPrint ("      include all                                                                \n");
12568         MrBayesPrint ("                                                                                 \n");
12569         MrBayesPrint ("   includes all of the characters in the analysis. Including all of the          \n");
12570         MrBayesPrint ("   characters (even if many of them are bad) is a very total-evidence-like       \n");
12571         MrBayesPrint ("   thing to do. Doing this will make a certain group of people very happy.       \n");
12572         MrBayesPrint ("   On the other hand, simply using this program would make those same people     \n");
12573         MrBayesPrint ("   unhappy.                                                                      \n");
12574         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12575         }
12576     else if (!strcmp(helpTkn, "Delete"))
12577         {
12578         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12579         MrBayesPrint ("   Delete                                                                        \n");
12580         MrBayesPrint ("                                                                                 \n");
12581         MrBayesPrint ("   This command deletes taxa from the analysis. The correct usage is:            \n");
12582         MrBayesPrint ("                                                                                 \n");
12583         MrBayesPrint ("      delete <name and/or number and/or taxset> ...                              \n");
12584         MrBayesPrint ("                                                                                 \n");
12585         MrBayesPrint ("   A list of the taxon names or taxon numbers (labelled 1 to ntax in the order   \n");
12586         MrBayesPrint ("   in the matrix) or taxset(s) can be used.  For example, the following:         \n");
12587         MrBayesPrint ("                                                                                 \n");
12588         MrBayesPrint ("      delete 1 2 Homo_sapiens                                                    \n");
12589         MrBayesPrint ("                                                                                 \n");
12590         MrBayesPrint ("   deletes taxa 1, 2, and the taxon labelled Homo_sapiens from the analysis.     \n");
12591         MrBayesPrint ("   You can also use \"all\" to delete all of the taxa. For example,              \n");
12592         MrBayesPrint ("                                                                                 \n");
12593         MrBayesPrint ("      delete all                                                                 \n");
12594         MrBayesPrint ("                                                                                 \n");
12595         MrBayesPrint ("   deletes all of the taxa from the analysis. Of course, a phylogenetic anal-    \n");
12596         MrBayesPrint ("   ysis that does not include any taxa is fairly uninteresting.                  \n");
12597         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12598         }
12599     else if (!strcmp(helpTkn, "Restore"))
12600         {
12601         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12602         MrBayesPrint ("   Restore                                                                       \n");
12603         MrBayesPrint ("                                                                                 \n");
12604         MrBayesPrint ("   This command restores taxa to the analysis. The correct usage is:             \n");
12605         MrBayesPrint ("                                                                                 \n");
12606         MrBayesPrint ("      restore <name and/or number and/or taxset> ...                             \n");
12607         MrBayesPrint ("                                                                                 \n");
12608         MrBayesPrint ("   A list of the taxon names or taxon numbers (labelled 1 to ntax in the order   \n");
12609         MrBayesPrint ("   in the matrix) or taxset(s) can be used.  For example, the following:         \n");
12610         MrBayesPrint ("                                                                                 \n");
12611         MrBayesPrint ("      restore 1 2 Homo_sapiens                                                   \n");
12612         MrBayesPrint ("                                                                                 \n");
12613         MrBayesPrint ("   restores taxa 1, 2, and the taxon labelled Homo_sapiens to the analysis.      \n");
12614         MrBayesPrint ("   You can also use \"all\" to restore all of the taxa. For example,             \n");
12615         MrBayesPrint ("                                                                                 \n");
12616         MrBayesPrint ("      restore all                                                                \n");
12617         MrBayesPrint ("                                                                                 \n");
12618         MrBayesPrint ("   restores all of the taxa to the analysis.                                     \n");
12619         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12620         }
12621     else if (!strcmp(helpTkn, "Quit"))
12622         {
12623         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12624         MrBayesPrint ("   Quit                                                                          \n");
12625         MrBayesPrint ("                                                                                 \n");
12626         MrBayesPrint ("   This command quits the program. The correct usage is:                         \n");
12627         MrBayesPrint ("                                                                                 \n");
12628         MrBayesPrint ("      quit                                                                       \n");
12629         MrBayesPrint ("                                                                                 \n");
12630         MrBayesPrint ("   It is a very easy command to use properly.                                    \n");
12631         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12632         }
12633     else if (!strcmp(helpTkn, "Disclaimer"))
12634         {
12635         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12636         MrBayesPrint ("   Disclaimer                                                                    \n");
12637         MrBayesPrint ("                                                                                 \n");
12638         MrBayesPrint ("   This command shows the disclaimer for the program. In short, the disclaimer   \n");
12639         MrBayesPrint ("   states that the authors are not responsible for any silly things you may do   \n");
12640         MrBayesPrint ("   to your computer or any unforseen but possibly nasty things the computer      \n");
12641         MrBayesPrint ("   program may inadvertently do to you.                                          \n");
12642         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12643         }
12644     else if (!strcmp(helpTkn, "Unlink"))
12645         {
12646         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12647         MrBayesPrint ("   Unlink                                                                        \n");
12648         MrBayesPrint ("                                                                                 \n");
12649         MrBayesPrint ("   This command unlinks model parameters across partitions of the data. The      \n");
12650         MrBayesPrint ("   correct usage is:                                                             \n");
12651         MrBayesPrint ("                                                                                 \n");
12652         MrBayesPrint ("      unlink <parameter name> = (<all> or <partition list>)                      \n");
12653         MrBayesPrint ("                                                                                 \n");
12654         MrBayesPrint ("   A little background is necessary to understand this command. Upon exe-        \n");
12655         MrBayesPrint ("   cution of a file, a default partition is set up. This partition refer-        \n");
12656         MrBayesPrint ("   enced either by its name (\"default\") or number (0). If your data are        \n");
12657         MrBayesPrint ("   all of one type, then this default partition does not actually divide up      \n");
12658         MrBayesPrint ("   your characters. However, if your datatype is mixed, then the default         \n");
12659         MrBayesPrint ("   partition contains as many divisions as there are datatypes in your           \n");
12660         MrBayesPrint ("   character matrix. Of course, you can also define other partitions, and        \n");
12661         MrBayesPrint ("   switch among them using the set command (\"set partition=<name/number>\").    \n");
12662         MrBayesPrint ("   Importantly, you can also assign model parameters to individual part-         \n");
12663         MrBayesPrint ("   itions or to groups of them using the \"applyto\" option in lset and          \n");
12664         MrBayesPrint ("   prset. When the program attempts to perform an analysis, the model is         \n");
12665         MrBayesPrint ("   set for individual partitions. If the same parameter applies to differ-       \n");
12666         MrBayesPrint ("   partitions and if that parameter has the same prior, then the program         \n");
12667         MrBayesPrint ("   will link the parameters: that is, it will use a single value for the         \n");
12668         MrBayesPrint ("   parameter. The program's default, then, is to strive for parsimony.           \n");
12669         MrBayesPrint ("   However, there are lots of cases where you may want unlink a parameter        \n");
12670         MrBayesPrint ("   across partitions. For example, you may want a different transition/          \n");
12671         MrBayesPrint ("   transversion rate ratio to apply to different partitions. This command        \n");
12672         MrBayesPrint ("   allows you to unlink the parameters, or to make them different across         \n");
12673         MrBayesPrint ("   partitions. The converse of this command is \"link\", which links to-         \n");
12674         MrBayesPrint ("   gether parameters that were previously told to be different. The list         \n");
12675         MrBayesPrint ("   of parameters that can be unlinked includes:                                  \n");
12676         MrBayesPrint ("                                                                                 \n");
12677         MrBayesPrint ("      Tratio          -- Transition/transversion rate ratio                      \n");
12678         MrBayesPrint ("      Revmat          -- Substitution rates of GTR model                         \n");
12679         MrBayesPrint ("      Omega           -- Nonsynonymous/synonymous rate ratio                     \n");
12680         MrBayesPrint ("      Statefreq       -- Character state frequencies                             \n");
12681         MrBayesPrint ("      Shape           -- Gamma/LNorm shape parameter                             \n");
12682         MrBayesPrint ("      Pinvar          -- Proportion of invariable sites                          \n");
12683         MrBayesPrint ("      Correlation     -- Correlation parameter of autodiscrete gamma             \n");
12684         MrBayesPrint ("      Ratemultiplier  -- Rate multiplier for partitions                          \n");
12685         MrBayesPrint ("      Switchrates     -- Switching rates for covarion model                      \n");
12686         MrBayesPrint ("      Topology        -- Topology of tree                                        \n");
12687         MrBayesPrint ("      Brlens          -- Branch lengths of tree                                  \n");
12688         MrBayesPrint ("      Speciationrate  -- Speciation rates for birth-death process                \n");
12689         MrBayesPrint ("      Extinctionrate  -- Extinction rates for birth-death process                \n");
12690     //  MrBayesPrint ("   Fossilizationrate  -- Fossilization rates for fossilized birth-death process  \n");
12691         MrBayesPrint ("      Popsize         -- Population size for coalescence process                 \n");
12692         MrBayesPrint ("      Growthrate      -- Growth rate of coalescence process                      \n");
12693         MrBayesPrint ("      Aamodel         -- Aminoacid rate matrix                                   \n");
12694         MrBayesPrint ("      Cpprate         -- Rate of Compound Poisson Process (CPP)                  \n");
12695         MrBayesPrint ("      Cppmultdev      -- Standard dev. of CPP rate multipliers (log scale)       \n");
12696         MrBayesPrint ("      Cppevents       -- CPP events                                              \n");
12697         MrBayesPrint ("      TK02var         -- Variance increase in TK02 relaxed clock model           \n");
12698         MrBayesPrint ("      Igrvar          -- Variance increase in IGR relaxed clock model            \n");
12699         MrBayesPrint ("      Mixedvar        -- Variance increase in Mixed relaxed clock model          \n");
12700     //  MrBayesPrint ("      TK02branchrates -- Branch rates of TK02  relaxed clock model               \n");
12701     //  MrBayesPrint ("      Igrbranchrates  -- Branch rates of IGR   relaxed clock model               \n");
12702     //  MrBayesPrint ("      Mixedbrchrates  -- Branch rates of Mixed relaxed clock model               \n");
12703         MrBayesPrint ("                                                                                 \n");
12704         MrBayesPrint ("   For example,                                                                  \n");
12705         MrBayesPrint ("                                                                                 \n");
12706         MrBayesPrint ("      unlink shape=(all)                                                         \n");
12707         MrBayesPrint ("                                                                                 \n");
12708         MrBayesPrint ("   unlinks the gamma/lnorm shape parameter across all partitions of the data.    \n");
12709         MrBayesPrint ("   You can use \"showmodel\" to see the current linking status of the            \n");
12710         MrBayesPrint ("   characters.                                                                   \n");
12711         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12712         }
12713     else if (!strcmp(helpTkn, "Link"))
12714         {
12715         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12716         MrBayesPrint ("   Link                                                                          \n");
12717         MrBayesPrint ("                                                                                 \n");
12718         MrBayesPrint ("   This command links model parameters across partitions of the data. The        \n");
12719         MrBayesPrint ("   correct usage is:                                                             \n");
12720         MrBayesPrint ("                                                                                 \n");
12721         MrBayesPrint ("      link <parameter name> = (<all> or <partition list>)                        \n");
12722         MrBayesPrint ("                                                                                 \n");
12723         MrBayesPrint ("   The list of parameters that can be linked includes:                           \n");
12724         MrBayesPrint ("                                                                                 \n");
12725         MrBayesPrint ("      Tratio          -- Transition/transversion rate ratio                      \n");
12726         MrBayesPrint ("      Revmat          -- Substitution rates of GTR model                         \n");
12727         MrBayesPrint ("      Omega           -- Nonsynonymous/synonymous rate ratio                     \n");
12728         MrBayesPrint ("      Statefreq       -- Character state frequencies                             \n");
12729         MrBayesPrint ("      Shape           -- Gamma/LNorm shape parameter                             \n");
12730         MrBayesPrint ("      Pinvar          -- Proportion of invariable sites                          \n");
12731         MrBayesPrint ("      Correlation     -- Correlation parameter of autodiscrete gamma             \n");
12732         MrBayesPrint ("      Ratemultiplier  -- Rate multiplier for partitions                          \n");
12733         MrBayesPrint ("      Switchrates     -- Switching rates for covarion model                      \n");
12734         MrBayesPrint ("      Topology        -- Topology of tree                                        \n");
12735         MrBayesPrint ("      Brlens          -- Branch lengths of tree                                  \n");
12736         MrBayesPrint ("      Speciationrate  -- Speciation rates for birth-death process                \n");
12737         MrBayesPrint ("      Extinctionrate  -- Extinction rates for birth-death process                \n");
12738     //  MrBayesPrint ("   Fossilizationrate  -- Fossilization rates for fossilized birth-death process  \n");
12739         MrBayesPrint ("      Popsize         -- Population size for coalescence process                 \n");
12740         MrBayesPrint ("      Growthrate      -- Growth rate of coalescence process                      \n");
12741         MrBayesPrint ("      Aamodel         -- Aminoacid rate matrix                                   \n");
12742         MrBayesPrint ("      Cpprate         -- Rate of Compound Poisson Process (CPP)                  \n");
12743         MrBayesPrint ("      Cppmultdev      -- Standard dev. of CPP rate multipliers (log scale)       \n");
12744         MrBayesPrint ("      Cppevents       -- CPP events                                              \n");
12745         MrBayesPrint ("      TK02var         -- Variance increase in TK02 relaxed clock model           \n");
12746         MrBayesPrint ("      Igrvar          -- Variance increase in IGR relaxed clock model            \n");
12747         MrBayesPrint ("      Mixedvar        -- Variance increase in Mixed relaxed clock model          \n");
12748     //  MrBayesPrint ("      TK02branchrates -- Branch rates of TK02  relaxed clock model               \n");
12749     //  MrBayesPrint ("      Igrbranchrates  -- Branch rates of IGR   relaxed clock model               \n");
12750     //  MrBayesPrint ("      Mixedbrchrates  -- Branch rates of Mixed relaxed clock model               \n");
12751         MrBayesPrint ("                                                                                 \n");
12752         MrBayesPrint ("   For example,                                                                  \n");
12753         MrBayesPrint ("                                                                                 \n");
12754         MrBayesPrint ("      link shape=(all)                                                           \n");
12755         MrBayesPrint ("                                                                                 \n");
12756         MrBayesPrint ("   links the gamma/lnorm shape parameter across all partitions of the data.      \n");
12757         MrBayesPrint ("   You can use \"showmodel\" to see the current linking status of the            \n");
12758         MrBayesPrint ("   characters. For more information on this command, see the help menu           \n");
12759         MrBayesPrint ("   for link's converse, unlink (\"help unlink\");                                \n");
12760         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12761         }
12762     else if (!strcmp(helpTkn, "Help"))
12763         {
12764         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12765         MrBayesPrint ("   Help                                                                          \n");
12766         MrBayesPrint ("                                                                                 \n");
12767         MrBayesPrint ("   This command provides useful information on the use of this program. The      \n");
12768         MrBayesPrint ("   correct usage is                                                              \n");
12769         MrBayesPrint ("                                                                                 \n");
12770         MrBayesPrint ("      help                                                                       \n");
12771         MrBayesPrint ("                                                                                 \n");
12772         MrBayesPrint ("   which gives a list of all available commands with a brief description of      \n");
12773         MrBayesPrint ("   each or                                                                       \n");
12774         MrBayesPrint ("                                                                                 \n");
12775         MrBayesPrint ("      help <command>                                                             \n");
12776         MrBayesPrint ("                                                                                 \n");
12777         MrBayesPrint ("   which gives detailed information on the use of <command>.                     \n");
12778         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12779         }
12780     else if (!strcmp(helpTkn, "Sump"))
12781         {
12782         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12783         MrBayesPrint ("   Sump                                                                          \n");
12784         MrBayesPrint ("                                                                                 \n");
12785         MrBayesPrint ("   During an MCMC analysis, MrBayes prints the sampled parameter values to one or\n");
12786         MrBayesPrint ("   more tab-delimited text files, one for each independent run in your analysis. \n");
12787         MrBayesPrint ("   The command 'Sump' summarizes the information in this parameter file or these \n");
12788         MrBayesPrint ("   parameter files. By default, the root of the parameter file name(s) is assumed\n");
12789         MrBayesPrint ("   to be the name of the last matrix-containing nexus file. MrBayes also remem-  \n");
12790         MrBayesPrint ("   bers the number of independent runs in the last analysis that you set up, re- \n");
12791         MrBayesPrint ("   gardless of whether you actually ran it. For instance, if there were two in-  \n");
12792         MrBayesPrint ("   dependent runs, which is the initial setting when you read in a new matrix,   \n");
12793         MrBayesPrint ("   MrBayes will assume that there are two parameter files with the endings       \n");
12794         MrBayesPrint ("   '.run1.p' and '.run2.p'. You can change the root of the file names and the    \n");
12795         MrBayesPrint ("   number of runs using the 'Filename' and 'Nruns' settings.                     \n");
12796         MrBayesPrint ("                                                                                 \n");
12797         MrBayesPrint ("   When you invoke the 'Sump' command, three items are output: (1) a generation  \n");
12798         MrBayesPrint ("   plot of the likelihood values; (2) estimates of the marginal likelihood of    \n");
12799         MrBayesPrint ("   the model; and (3) a table with the mean, variance, and 95 percent credible   \n");
12800         MrBayesPrint ("   interval for the sampled parameters. All three items are output to screen.    \n");
12801         MrBayesPrint ("   The table of marginal likelihoods is also printed to a file with the ending   \n");
12802         MrBayesPrint ("   '.lstat' and the parameter table to a file with the ending '.pstat'. For some \n");
12803         MrBayesPrint ("   model parameters, there may also be a '.mstat' file.                          \n");
12804         MrBayesPrint ("                                                                                 \n");
12805         MrBayesPrint ("   When running 'Sump' you typically want to discard a specified number or       \n");
12806         MrBayesPrint ("   fraction of samples from the beginning of the chain as the burn in. This is   \n");
12807         MrBayesPrint ("   done using the same mechanism used by the 'mcmc' command. That is, if you     \n");
12808         MrBayesPrint ("   run an mcmc analysis with a relative burn in of 25 %% of samples for con-     \n");
12809         MrBayesPrint ("   vergence diagnostics, then the same burn in will be used for a subsequent     \n");
12810         MrBayesPrint ("   sump command, unless a different burn in is specified. That is, issuing       \n");
12811         MrBayesPrint ("                                                                                 \n");
12812         MrBayesPrint ("   sump                                                                          \n");
12813         MrBayesPrint ("                                                                                 \n");
12814         MrBayesPrint ("   immediately after 'mcmc', will result in using the same burn in settings as   \n");
12815         MrBayesPrint ("   for the 'mcmc' command. All burnin settings are reset to default values every \n");
12816         MrBayesPrint ("   time a new matrix is read in, namely relative burnin ('relburnin=yes') with   \n");
12817         MrBayesPrint ("   25 %% of samples discarded ('burninfrac = 0.25').                             \n");
12818         MrBayesPrint ("                                                                                 \n");
12819         MrBayesPrint ("   Options:                                                                      \n");
12820         MrBayesPrint ("                                                                                 \n");
12821         MrBayesPrint ("   Relburnin    -- If this option is set to 'Yes', then a proportion of the      \n");
12822         MrBayesPrint ("                   samples will be discarded as burnin when calculating summary  \n");
12823         MrBayesPrint ("                   statistics. The proportion to be discarded is set with        \n");
12824         MrBayesPrint ("                   'Burninfrac' (see below). When the 'Relburnin' option is set  \n");
12825         MrBayesPrint ("                   to 'No', then a specific number of samples is discarded       \n");
12826         MrBayesPrint ("                   instead. This number is set by 'Burnin' (see below). Note that\n");
12827         MrBayesPrint ("                   the burnin setting is shared across the 'sumt', 'sump', and   \n");
12828         MrBayesPrint ("                   'mcmc' commands.                                              \n");
12829         MrBayesPrint ("   Burnin       -- Determines the number of samples (not generations) that will  \n");
12830         MrBayesPrint ("                   be discarded when summary statistics are calculated. The      \n");
12831         MrBayesPrint ("                   value of this option is only applicable when 'Relburnin' is   \n");
12832         MrBayesPrint ("                   set to 'No'.                                                  \n");
12833         MrBayesPrint ("   Burninfrac   -- Determines the fraction of samples that will be discarded when\n");
12834         MrBayesPrint ("                   summary statistics are calculated. The setting only takes     \n");
12835         MrBayesPrint ("                   effect if 'Relburnin' is set to 'Yes'.                        \n");
12836         MrBayesPrint ("   Nruns        -- Determines how many '.p' files from independent analyses that \n");
12837         MrBayesPrint ("                   will be summarized. If Nruns > 1 then the names of the files  \n");
12838         MrBayesPrint ("                   are derived from 'Filename' by adding '.run1.p', '.run2.p',   \n");
12839         MrBayesPrint ("                   etc. If Nruns=1, then the single file name is obtained by     \n");
12840         MrBayesPrint ("                   adding '.p' to 'Filename'.                                    \n");
12841         MrBayesPrint ("   Filename     -- The name of the file to be summarized. This is the base of the\n");
12842         MrBayesPrint ("                   file name to which endings are added according to the current \n");
12843         MrBayesPrint ("                   setting of the 'Nruns' parameter. If 'Nruns' is 1, then only  \n");
12844         MrBayesPrint ("                   '.p' is added to the file name. Otherwise, the endings will   \n");
12845         MrBayesPrint ("                   be '.run1.p', '.run2.p', etc.                                 \n");
12846         MrBayesPrint ("   Outputname   -- Base name of the file(s) to which 'Sump' results will be      \n");
12847         MrBayesPrint ("                   printed.                                                      \n");
12848         MrBayesPrint ("   Hpd          -- Determines whether credibility intervals will be given as the \n");
12849         MrBayesPrint ("                   region of Highest Posterior Density ('Yes') or as the interval\n");
12850         MrBayesPrint ("                   containing the median 95 %% of sampled values ('No').         \n");
12851         MrBayesPrint ("   Minprob      -- Determines the minimum probability of submodels to be included\n");
12852         MrBayesPrint ("                   in summary statistics. Only applicable to models that explore \n");
12853         MrBayesPrint ("                   submodel spaces, like 'nst=mixed' and 'aamodelpr=mixed'.      \n");
12854         MrBayesPrint ("                                                                                 \n");
12855         MrBayesPrint ("   Current settings:                                                             \n");
12856         MrBayesPrint ("                                                                                 \n");
12857         MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
12858         MrBayesPrint ("   --------------------------------------------------------                      \n");
12859         MrBayesPrint ("   Relburnin       Yes/No                   %s                                   \n", chainParams.relativeBurnin == YES ? "Yes" : "No");
12860         MrBayesPrint ("   Burnin          <number>                 %d                                   \n", chainParams.chainBurnIn);
12861         MrBayesPrint ("   Burninfrac      <number>                 %1.2lf                               \n", chainParams.burninFraction);
12862         MrBayesPrint ("   Nruns           <number>                 %d                                   \n", sumpParams.numRuns);
12863         if (sumpParams.numRuns == 1)
12864             MrBayesPrint ("   Filename        <name>                   %s<.p>\n", sumpParams.sumpFileName);
12865         else
12866             MrBayesPrint ("   Filename        <name>                   %s<.run<i>.p>\n", sumpParams.sumpFileName);
12867         MrBayesPrint ("   Outputname      <name>                   %s<.pstat etc>\n", sumpParams.sumpOutfile);
12868         MrBayesPrint ("   Hpd             Yes/No                   %s                                   \n", sumpParams.HPD == YES ? "Yes" : "No");
12869         MrBayesPrint ("   Minprob         <number>                 %1.3lf                               \n", sumpParams.minProb);
12870         MrBayesPrint ("                                                                                 \n");
12871         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12872         }
12873     else if (!strcmp(helpTkn, "Sumss"))
12874         {
12875         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12876         MrBayesPrint ("   Sumss                                                                         \n");
12877         MrBayesPrint ("                                                                                 \n");
12878         MrBayesPrint ("   This command summarizes results of stepping stone analyses. It is a tool to   \n");
12879         MrBayesPrint ("   investigate the obtained results, and to help find the proper step burn-in.   \n");
12880         MrBayesPrint ("   To get more help information on stepping-stone analyses, use 'help ss'.       \n");
12881         MrBayesPrint ("                                                                                 \n");
12882         MrBayesPrint ("   During stepping-stone analysis, MrBayes collects the sampled likelihoods in   \n");
12883         MrBayesPrint ("   order to estimate the marginal likelihood at the end. It also prints the sam- \n");
12884         MrBayesPrint ("   pled parameter values to one or more tab-delimited text files, one for each   \n");
12885         MrBayesPrint ("   independent run in your analysis. The command 'Sumss' summarizes likelihood   \n");
12886         MrBayesPrint ("   values stored in these parameter files and calculates marginal likelihood es- \n");
12887         MrBayesPrint ("   timates. The names of the files that are summarized are exactly the same as   \n");
12888         MrBayesPrint ("   the names of the files used for the 'sump' command. In fact, the 'filename'   \n");
12889         MrBayesPrint ("   setting is a shared setting for the 'sump' and 'sumss' commands. That is, if  \n");
12890         MrBayesPrint ("   you change the setting in one of the commands, it would change the setting in \n");
12891         MrBayesPrint ("   the other command as well.                                                    \n");
12892         MrBayesPrint ("                                                                                 \n");
12893         MrBayesPrint ("   When you invoke the 'Sumss' command, three items are output: (1) 'Step contri-\n");
12894         MrBayesPrint ("   bution table' - summarizes the contribution of each step to the overall esti- \n");
12895         MrBayesPrint ("   mate; (2) 'Step plot' - plot of the likelihood values for the initial burn-in \n");
12896         MrBayesPrint ("   phase or a chosen step in the stepping-stone algorithm; (3) 'Joined plot' -   \n");
12897         MrBayesPrint ("   summarizes sampling across all steps in the algorithm.                        \n");
12898         MrBayesPrint ("                                                                                 \n");
12899         MrBayesPrint ("   Step contribution table                                                       \n");
12900         MrBayesPrint ("   The printed table is similar to the one output to the .ss file. The main pur- \n");
12901         MrBayesPrint ("   pose of the table is to summarize marginal likelihood for different values of \n");
12902         MrBayesPrint ("   the step burn-in after the stepping stone  analysis has finished. The burn-in \n");
12903         MrBayesPrint ("   is controlled by the 'Relburnin', 'Burnin' and 'Burninfrac' settings.         \n");
12904         MrBayesPrint ("   Note that during stepping-stone analyses, step contributions to marginal      \n");
12905         MrBayesPrint ("   likelihood are calculated based on all generations excluding burn-in. 'Sumss' \n");
12906         MrBayesPrint ("   on the other hand makes estimates based only on the sampled generations. This \n");
12907         MrBayesPrint ("   may lead to slight difference in results compared to the one printed to the   \n");
12908         MrBayesPrint ("   .ss file.                                                                     \n");
12909         MrBayesPrint ("                                                                                 \n");
12910         MrBayesPrint ("   Step plot                                                                     \n");
12911         MrBayesPrint ("   The main objective of the plot is to provide a close look at a given step     \n");
12912         MrBayesPrint ("   in the analysis. Which step is printed here is defined by the 'Steptoplot'    \n");
12913         MrBayesPrint ("   setting.  The plot could be used to inspect if the chosen step burn-in is     \n");
12914         MrBayesPrint ("   appropriate for the given step. It could also be used to check if the initial \n");
12915         MrBayesPrint ("   burn-in phase has converged. Note that the amount of discarded samples is     \n");
12916         MrBayesPrint ("   controlled by the 'Discardfrac' setting, and not by the ordinary burn-in      \n");
12917         MrBayesPrint ("   settings.                                                                     \n");
12918         MrBayesPrint ("                                                                                 \n");
12919         MrBayesPrint ("   Joined plot                                                                   \n");
12920         MrBayesPrint ("   Different steps sample from different power posterior distributions. When we  \n");
12921         MrBayesPrint ("   switch from one distribution to another, it takes some number of generations  \n");
12922         MrBayesPrint ("   before the chain settles at the correct stationary distribution. This lag is  \n");
12923         MrBayesPrint ("   called a 'temperature lag' and if the corresponding samples are not removed,  \n");
12924         MrBayesPrint ("   it will result in a biased estimate. It is difficult to determine the lag be- \n");
12925         MrBayesPrint ("   forehand, but MrBayes allows you to explore different step burn-in settings   \n");
12926         MrBayesPrint ("   after you have finished the stepping-stone algorithm, without having to rerun \n");
12927         MrBayesPrint ("   the whole analysis. The 'Joined plot' helps to facilitate the choice of the   \n");
12928         MrBayesPrint ("   right step burn-in. The plot summarizes samples across all steps and gives you\n");
12929         MrBayesPrint ("   a quick overview of the whole analysis.                                       \n");
12930         MrBayesPrint ("                                                                                 \n");
12931         MrBayesPrint ("   Specifically, the following procedure is used to obtain the joined plot. Each \n");
12932         MrBayesPrint ("   step has the same number N of samples taken. We number each sample 1 to N     \n");
12933         MrBayesPrint ("   within steps according to the order in which the samples are taken. The first \n");
12934         MrBayesPrint ("   sample in each step is numbered 1, and the last sample is N. For each number i\n");
12935         MrBayesPrint ("   in [1,..., N], we sum up log likelihoods for all samples numbered i across all\n");
12936         MrBayesPrint ("   steps. The joined plot is a graph of the step number versus the normalized    \n");
12937         MrBayesPrint ("   sums we get in the procedure describe above. This directly visualizes the tem-\n");
12938         MrBayesPrint ("   perature lag and allows you to select the appropriate step burn-in.           \n");
12939         MrBayesPrint ("                                                                                 \n");
12940         MrBayesPrint ("   Ideally, after you discard the appropriate step burn-in, the graph should     \n");
12941         MrBayesPrint ("   appear as white noise around the estimated value. If you see an increasing or \n");
12942         MrBayesPrint ("   decreasing tendency in the beginning of the graph, you should increase the    \n");
12943         MrBayesPrint ("   step burn-in. If you see an increasing or decreasing tendency across the whole\n");
12944         MrBayesPrint ("   graph, then the initial burn-in phase was not long enough. In this case, you  \n");
12945         MrBayesPrint ("   need to rerun the analysis with a longer initial burn-in.                     \n");
12946         MrBayesPrint ("                                                                                 \n");
12947         MrBayesPrint ("   To make it easier to observe tendencies in the plotted graph you can choose   \n");
12948         MrBayesPrint ("   different levels of curve smoothing. If 'Smoothing' is set to k, it means that\n");
12949         MrBayesPrint ("   for each step i we take an average over step i and k neighboring samples in   \n");
12950         MrBayesPrint ("   both directions, i.e., the k-smoothed estimate for step i is an average over  \n");
12951         MrBayesPrint ("   values for steps [i-k,...,i+k].                                               \n");
12952         MrBayesPrint ("                                                                                 \n");
12953         MrBayesPrint ("                                                                                 \n");
12954         MrBayesPrint ("   Options:                                                                      \n");
12955         MrBayesPrint ("                                                                                 \n");
12956         MrBayesPrint ("   Allruns      -- If set to 'Yes', it forces all runs to be printed on the same \n");
12957         MrBayesPrint ("                   graph when drawing joined and step plots. If set to 'No', each\n");
12958         MrBayesPrint ("                   run is printed on a separat plot.                             \n");
12959         MrBayesPrint ("   Askmore      -- Long analyses may produce huge .p files. Reading in them may  \n");
12960         MrBayesPrint ("                   take several minutes. If you want to investigate different    \n");
12961         MrBayesPrint ("                   aspects of your analyses, it could be very inconvenient to    \n");
12962         MrBayesPrint ("                   wait for several minutes each time you want to get a new sum- \n");
12963         MrBayesPrint ("                   mary for different settings. If you set 'Askmore' to 'YES',   \n");
12964         MrBayesPrint ("                   sumss will read .p files only once. After responding to the   \n");
12965         MrBayesPrint ("                   original query, it will interactivaly ask you if you wish to  \n");
12966         MrBayesPrint ("                   produce more tables and plots for different settings of       \n");
12967         MrBayesPrint ("                   'Burnin' or 'Smoothing' (see below).                          \n");
12968         MrBayesPrint ("   Relburnin    -- If this option is set to 'Yes', then a proportion of the      \n");
12969         MrBayesPrint ("                   samples from each step will be discarded as burnin when calcu-\n");
12970         MrBayesPrint ("                   lsting summary statistics. The proportion to be discarded is  \n");
12971         MrBayesPrint ("                   set with 'Burninfrac' (see below). When the 'Relburnin' option\n");
12972         MrBayesPrint ("                   is set to 'No', then a specific number of samples is discarded\n");
12973         MrBayesPrint ("                   instead. This number is set by 'Burnin'. Note that the burnin \n");
12974         MrBayesPrint ("                   settings --- 'Relburnin', 'Burnin', and 'Burninfrac' --- are  \n");
12975         MrBayesPrint ("                   shared across the 'sumt', 'sump', 'sumss' and 'mcmc' commands.\n");
12976         MrBayesPrint ("   Burnin       -- Determines the number of samples (not generations) that will  \n");
12977         MrBayesPrint ("                   be discarded from each step when summary statistics are calcu-\n");
12978         MrBayesPrint ("                   lated. The value of this option is only applicable when       \n");
12979         MrBayesPrint ("                   'Relburnin' is set to 'No'.                                   \n");
12980         MrBayesPrint ("   Burninfrac   -- Determines the fraction of samples that will be discarded from\n");
12981         MrBayesPrint ("                   each step when summary statistics are calculated. The setting \n");
12982         MrBayesPrint ("                   only takes effect if 'Relburnin' is set to 'Yes'.             \n");
12983         MrBayesPrint ("   Discardfrac  -- Determines the fraction of samples that will be discarded when\n");
12984         MrBayesPrint ("                   a step plot is printed. It is similar to the 'Burninfrac' set-\n");
12985         MrBayesPrint ("                   ting, but unlike 'Burninfrac' it is used only for better vis- \n");
12986         MrBayesPrint ("                   ualization of the step plot. It has no effect on the number of\n");
12987         MrBayesPrint ("                   samples discarded during marginal likelihood computation.     \n");
12988         MrBayesPrint ("   Filename     -- The name of the file to be summarized. This is the base of the\n");
12989         MrBayesPrint ("                   file name to which endings are added according to the current \n");
12990         MrBayesPrint ("                   setting of the 'Nruns' parameter. If 'Nruns' is 1, then only  \n");
12991         MrBayesPrint ("                   '.p' is added to the file name. Otherwise, the endings will   \n");
12992         MrBayesPrint ("                   be '.run1.p', '.run2.p', etc. Note that the 'Filename' setting\n");
12993         MrBayesPrint ("                   is shared with 'sump' command.                                \n");
12994         MrBayesPrint ("   Nruns        -- Determines how many '.p' files from independent analyses that \n");
12995         MrBayesPrint ("                   will be summarized. If Nruns > 1 then the names of the files  \n");
12996         MrBayesPrint ("                   are derived from 'Filename' by adding '.run1.p', '.run2.p',   \n");
12997         MrBayesPrint ("                   etc. If Nruns=1, then the single file name is obtained by     \n");
12998         MrBayesPrint ("                   adding '.p' to 'Filename'.                                    \n");
12999         MrBayesPrint ("   Steptoplot   -- Defines which step will be printed in the step plot.If the    \n");
13000         MrBayesPrint ("                   value is set to 0, then the initial sample from the posterior \n");
13001         MrBayesPrint ("                   will be used.                                                 \n");
13002         MrBayesPrint ("   Smoothing    -- Determines smoothing of the joined plot (see above). A value  \n");
13003         MrBayesPrint ("                   equal to 0 results in no smoothing.                           \n");
13004         MrBayesPrint ("                                                                                 \n");
13005         MrBayesPrint ("   Current settings:                                                             \n");
13006         MrBayesPrint ("                                                                                 \n");
13007         MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
13008         MrBayesPrint ("   --------------------------------------------------------                      \n");
13009         MrBayesPrint ("   Allruns         Yes/No                   %s                                   \n", sumssParams.allRuns == YES ? "Yes" : "No");
13010         MrBayesPrint ("   Askmore         Yes/No                   %s                                   \n", sumssParams.askForMorePlots == YES ? "Yes" : "No");
13011         MrBayesPrint ("   Relburnin       Yes/No                   %s                                   \n", chainParams.relativeBurnin == YES ? "Yes" : "No");
13012         MrBayesPrint ("   Burnin          <number>                 %d                                   \n", chainParams.chainBurnIn);
13013         MrBayesPrint ("   Burninfrac      <number>                 %1.2lf                               \n", chainParams.burninFraction);
13014         MrBayesPrint ("   Discardfrac     <number>                 %1.2lf                               \n", sumssParams.discardFraction);
13015         if (sumpParams.numRuns == 1)
13016             MrBayesPrint ("   Filename        <name>                   %s<.p>\n", sumpParams.sumpFileName);
13017         else
13018             MrBayesPrint ("   Filename        <name>                   %s<.run<i>.p>\n", sumpParams.sumpFileName);
13019         MrBayesPrint ("   Nruns           <number>                 %d                                   \n", sumpParams.numRuns);
13020         MrBayesPrint ("   Steptoplot      <number>                 %d                                   \n", sumssParams.stepToPlot);
13021         MrBayesPrint ("   Smoothing       <number>                 %d                                   \n", sumssParams.smoothing);
13022         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13023         }
13024     else if (!strcmp(helpTkn, "Comparetree"))
13025         {
13026         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13027         MrBayesPrint ("   Comparetree                                                                   \n");
13028         MrBayesPrint ("                                                                                 \n");
13029         MrBayesPrint ("   This command compares the trees in two files, called \"filename1\" and        \n");
13030         MrBayesPrint ("   \"filename2\". It will output a bivariate plot of the split frequencies       \n");
13031         MrBayesPrint ("   as well as plots of the tree distance as a function of the generation. The    \n");
13032         MrBayesPrint ("   plots can be used to get a quick indication of whether two runs have con-     \n");
13033         MrBayesPrint ("   verged onto the same set of trees. The \"Comparetree\" command will also      \n");
13034         MrBayesPrint ("   produce a \".pairs\" file and a \".dists\" file (these file endings are added \n");
13035         MrBayesPrint ("   to the end of the \"Outputname\"). The \".pairs\" file contains the paired    \n");
13036         MrBayesPrint ("   split frequencies from the two tree samples; the \".dists\" file contains the \n");
13037         MrBayesPrint ("   tree distance values.                                                         \n");
13038         MrBayesPrint ("                                                                                 \n");
13039         MrBayesPrint ("   Note that the \"Sumt\" command provides a different set of convergence diag-  \n");
13040         MrBayesPrint ("   nostics tools that you may also want to explore. Unlike \"Comparetree\",      \n");
13041         MrBayesPrint ("   \"Sumt\" can compare more than two tree samples and will calculate consensus  \n");
13042         MrBayesPrint ("   trees and split frequencies from the pooled samples.                          \n");
13043         MrBayesPrint ("                                                                                 \n");
13044         MrBayesPrint ("   Options:                                                                      \n");
13045         MrBayesPrint ("                                                                                 \n");
13046         MrBayesPrint ("   Relburnin     -- If this option is set to 'Yes', then a proportion of the     \n");
13047         MrBayesPrint ("                    samples will be discarded as burnin when calculating summary \n");
13048         MrBayesPrint ("                    statistics. The proportion to be discarded is set with       \n");
13049         MrBayesPrint ("                    Burninfrac (see below). When the Relburnin option is set to  \n");
13050         MrBayesPrint ("                    'No', then a specific number of samples is discarded instead.\n");
13051         MrBayesPrint ("                    This number is set by Burnin (see below). Note that the      \n");
13052         MrBayesPrint ("                    burnin setting is shared with the 'mcmc', 'sumt', 'sump' and \n");
13053         MrBayesPrint ("                    'plot' commands.                                             \n");
13054         MrBayesPrint ("   Burnin        -- Determines the number of samples (not generations) that will \n");
13055         MrBayesPrint ("                    be discarded when summary statistics are calculated. The     \n");
13056         MrBayesPrint ("                    value of this option is only relevant when Relburnin is set  \n");
13057         MrBayesPrint ("                    to 'No'.                                                     \n");
13058         MrBayesPrint ("   BurninFrac    -- Determines the fraction of samples that will be discarded    \n");
13059         MrBayesPrint ("                    when summary statistics are calculated. The value of this    \n");
13060         MrBayesPrint ("                    option is only relevant when Relburnin is set to 'Yes'.      \n");
13061         MrBayesPrint ("                    Example: A value for this option of 0.25 means that 25%% of  \n");
13062         MrBayesPrint ("                    the samples will be discarded.                               \n");
13063         MrBayesPrint ("   Minpartfreq   -- The minimum probability of partitions to include in summary  \n");
13064         MrBayesPrint ("                    statistics.                                                  \n");
13065         MrBayesPrint ("   Filename1     -- The name of the first tree file to compare.                  \n");
13066         MrBayesPrint ("   Filename2     -- The name of the second tree file to compare.                 \n");
13067         MrBayesPrint ("   Outputname    -- Name of the file to which 'comparetree' results will be      \n");
13068         MrBayesPrint ("                    printed.                                                     \n");
13069         MrBayesPrint ("                                                                                 \n");
13070         MrBayesPrint ("   Current settings:                                                             \n");
13071         MrBayesPrint ("                                                                                 \n");
13072         MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
13073         MrBayesPrint ("   --------------------------------------------------------                      \n");
13074         MrBayesPrint ("   Relburnin       Yes/No                   %s                                   \n", chainParams.relativeBurnin == YES ? "Yes" : "No");
13075         MrBayesPrint ("   Burnin          <number>                 %d                                   \n", chainParams.chainBurnIn);
13076         MrBayesPrint ("   Burninfrac      <number>                 %1.2lf                               \n", chainParams.burninFraction);
13077         MrBayesPrint ("   Minpartfreq     <number>                 %1.2lf                               \n", comptreeParams.minPartFreq);
13078         MrBayesPrint ("   Filename1       <name>                   %s                                   \n", comptreeParams.comptFileName1);
13079         MrBayesPrint ("   Filename2       <name>                   %s                                   \n", comptreeParams.comptFileName2);
13080         MrBayesPrint ("   Outputname      <name>                   %s                                   \n", comptreeParams.comptOutfile);
13081         MrBayesPrint ("                                                                                 \n");
13082         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13083         }
13084     else if (!strcmp(helpTkn, "Sumt"))
13085         {
13086         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13087         MrBayesPrint ("   Sumt                                                                          \n");
13088         MrBayesPrint ("                                                                                 \n");
13089         MrBayesPrint ("   This command is used to produce summary statistics for trees sampled during   \n");
13090         MrBayesPrint ("   a Bayesian MCMC analysis. You can either summarize trees from one individual  \n");
13091         MrBayesPrint ("   analysis, or trees coming from several independent analyses. In either case,  \n");
13092         MrBayesPrint ("   all the sampled trees are read in and the proportion of the time any single   \n");
13093         MrBayesPrint ("   taxon bipartition (split) is found is counted. The proportion of the time that\n");
13094         MrBayesPrint ("   the bipartition is found is an approximation of the posterior probability of  \n");
13095         MrBayesPrint ("   the bipartition. (Remember that a taxon bipartition is defined by removing a  \n");
13096         MrBayesPrint ("   branch on the tree, dividing the tree into those taxa to the left and right   \n");
13097         MrBayesPrint ("   of the removed branch. This set is called a taxon bipartition.) The branch    \n");
13098         MrBayesPrint ("   length of the bipartition is also recorded, if branch lengths have been saved \n");
13099         MrBayesPrint ("   to file. The result is a list of the taxon bipartitions found, the frequency  \n");
13100         MrBayesPrint ("   with which they were found, the posterior probability of the bipartition      \n");
13101         MrBayesPrint ("   and, the mean and variance of the branch lengths or node depths, and various  \n");
13102         MrBayesPrint ("   other statistics.                                                             \n");
13103         MrBayesPrint ("                                                                                 \n");
13104         MrBayesPrint ("   The key to the partitions is output to a file with the suffix '.parts'. The   \n");
13105         MrBayesPrint ("   summary statistics pertaining to bipartition probabilities are output to a    \n");
13106         MrBayesPrint ("   file with the suffix '.tstat', and the statistics pertaining to branch or node\n");
13107         MrBayesPrint ("   parameters are output to a file with the suffix '.vstat'.                     \n");
13108         MrBayesPrint ("                                                                                 \n");
13109         MrBayesPrint ("   A consensus tree is also printed to a file with the suffix '.con.tre' and     \n");
13110         MrBayesPrint ("   printed to the screen as a cladogram, and as a phylogram if branch lengths    \n");
13111         MrBayesPrint ("   have been saved. The consensus tree is either a 50 percent majority rule tree \n");
13112         MrBayesPrint ("   or a majority rule tree showing all compatible partitions. If branch lengths  \n");
13113         MrBayesPrint ("   have been recorded during the run, the '.con.tre' file will contain a consen- \n");
13114         MrBayesPrint ("   sus tree with branch lengths and interior nodes labelled with support values. \n");
13115         MrBayesPrint ("   By default, the consensus tree will also contain other summary information in \n");
13116         MrBayesPrint ("   a format understood by the program 'FigTree'. To use a simpler format under-  \n");
13117         MrBayesPrint ("   stood by other tree-drawing programs, such as 'TreeView', set 'Conformat' to  \n");
13118         MrBayesPrint ("   'Simple'.                                                                     \n");
13119         MrBayesPrint ("                                                                                 \n");
13120         MrBayesPrint ("   MrBayes alo produces a file with the ending \".trprobs\" that contains a list \n");
13121         MrBayesPrint ("   of all the trees that were found during the MCMC analysis, sorted by their    \n");
13122         MrBayesPrint ("   probabilities. This list of trees can be used to construct a credible set of  \n");
13123         MrBayesPrint ("   trees. For example, if you want to construct a 95 percent credible set of     \n");
13124         MrBayesPrint ("   trees, you include all of those trees whose cumulative probability is less    \n");
13125         MrBayesPrint ("   than or equal to 0.95. You have the option of displaying the trees to the     \n");
13126         MrBayesPrint ("   screen using the \"Showtreeprobs\" option. The default is to not display the  \n");
13127         MrBayesPrint ("   trees to the screen; the number of different trees sampled by the chain can   \n");
13128         MrBayesPrint ("   be quite large. If you are analyzing a large set of taxa, you may actually    \n");
13129         MrBayesPrint ("   want to skip the calculation of tree probabilities entirely by setting        \n");
13130         MrBayesPrint ("   'Calctreeprobs' to 'No'.                                                      \n");
13131         MrBayesPrint ("                                                                                 \n");
13132         MrBayesPrint ("   When calculating summary statistics you probably want to skip those trees that\n");
13133         MrBayesPrint ("   were sampled in the initial part of the run, the so-called burn-in period. The\n");
13134         MrBayesPrint ("   number of skipped samples is controlled by the 'Relburnin', 'Burnin', and     \n");
13135         MrBayesPrint ("   'Burninfrac' settings, just as for the 'Mcmc' command. Since version 3.2.0,   \n");
13136         MrBayesPrint ("   the burn-in settings are shared across the 'Sumt', 'Sump' and 'Mcmc' commands.\n");
13137         MrBayesPrint ("   That is, changing the burn-in setting for one command will change the settings\n");
13138         MrBayesPrint ("   for subsequent calls to any of the other commands.                            \n");
13139         MrBayesPrint ("                                                                                 \n");
13140         MrBayesPrint ("   If you are summarizing the trees sampled in several independent analyses,     \n");
13141         MrBayesPrint ("   such as those resulting from setting the 'Nruns' option of the 'Mcmc' command \n");
13142         MrBayesPrint ("   to a value larger than 1, MrBayes will also calculate convergence diagnostics \n");
13143         MrBayesPrint ("   for the sampled topologies and branch lengths. These values can help you      \n");
13144         MrBayesPrint ("   determine whether it is likely that your chains have converged.               \n");
13145         MrBayesPrint ("                                                                                 \n");
13146         MrBayesPrint ("   The 'Sumt' command expands the 'Filename' according to the current values of  \n");
13147         MrBayesPrint ("   the 'Nruns' and 'Ntrees' options. For instance, if both 'Nruns' and 'Ntrees'  \n");
13148         MrBayesPrint ("   are set to 1, 'Sumt' will try to open a file named '<Filename>.t'. If 'Nruns' \n");
13149         MrBayesPrint ("   is set to 2 and 'Ntrees' to 1, then 'Sumt' will open two files, the first     \n");
13150         MrBayesPrint ("   named '<Filename>.run1.t' and the second '<Filename>.run2.t', etc. By default,\n");
13151         MrBayesPrint ("   the 'Filename' option is set such that 'Sumt' automatically summarizes all the\n");
13152         MrBayesPrint ("   results from your immediately preceding 'Mcmc' command. You can also use the  \n");
13153         MrBayesPrint ("   'Sumt' command to summarize tree samples in older analyses. If you want to do \n");
13154         MrBayesPrint ("   that, remember to first read in a matrix so that MrBayes knows what taxon     \n");
13155         MrBayesPrint ("   names to expect in the trees. Then set the 'Nruns', 'Ntrees' and 'Filename'   \n");
13156         MrBayesPrint ("   options appropriately if they differ from the MrBayes defaults.               \n");
13157         MrBayesPrint ("                                                                                 \n");
13158         MrBayesPrint ("   Options:                                                                      \n");
13159         MrBayesPrint ("                                                                                 \n");
13160         MrBayesPrint ("   Relburnin     -- If this option is set to YES, then a proportion of the       \n");
13161         MrBayesPrint ("                    samples will be discarded as burnin when calculating summary \n");
13162         MrBayesPrint ("                    statistics. The proportion to be discarded is set with       \n");
13163         MrBayesPrint ("                    Burninfrac (see below). When the Relburnin option is set to  \n");
13164         MrBayesPrint ("                    NO, then a specific number of samples is discarded instead.  \n");
13165         MrBayesPrint ("                    This number is set by Burnin (see below). Note that the      \n");
13166         MrBayesPrint ("                    burnin setting is shared across the 'sumt', 'sump', and      \n");
13167         MrBayesPrint ("                    'mcmc' commands.                                             \n");
13168         MrBayesPrint ("   Burnin        -- Determines the number of samples (not generations) that will \n");
13169         MrBayesPrint ("                    be discarded when summary statistics are calculated. The     \n");
13170         MrBayesPrint ("                    value of this option is only relevant when Relburnin is set  \n");
13171         MrBayesPrint ("                    to NO.                                                       \n");
13172         MrBayesPrint ("   BurninFrac    -- Determines the fraction of samples that will be discarded    \n");
13173         MrBayesPrint ("                    when summary statistics are calculated. The value of this    \n");
13174         MrBayesPrint ("                    option is only relevant when Relburnin is set to YES.        \n");
13175         MrBayesPrint ("                    Example: A value for this option of 0.25 means that 25%% of  \n");
13176         MrBayesPrint ("                    the samples will be discarded.                               \n");
13177         MrBayesPrint ("   Nruns         -- Determines how many '.t' files from independent analyses that\n");
13178         MrBayesPrint ("                    will be summarized. If Nruns > 1 then the names of the files \n");
13179         MrBayesPrint ("                    are derived from 'Filename' by adding '.run1.t', '.run2.t',  \n");
13180         MrBayesPrint ("                    etc. If Nruns=1 and Ntrees=1 (see below), then only '.t' is  \n");
13181         MrBayesPrint ("                    added to 'Filename'.                                         \n");
13182         MrBayesPrint ("   Ntrees        -- Determines how many trees there are in the sampled model. If \n");
13183         MrBayesPrint ("                    'Ntrees' > 1 then the names of the files are derived from    \n");
13184         MrBayesPrint ("                    'Filename' by adding '.tree1.t', '.tree2.t', etc. If there   \n");
13185         MrBayesPrint ("                    are both multiple trees and multiple runs, the filenames will\n");
13186         MrBayesPrint ("                    be '<Filename>.tree1.run1.t', '<Filename>.tree1.run2.t', etc.\n");
13187         MrBayesPrint ("   Filename      -- The name of the file(s) to be summarized. This is the base of\n");
13188         MrBayesPrint ("                    the file name, to which endings are added according to the   \n");
13189         MrBayesPrint ("                    current settings of the 'Nruns' and 'Ntrees' options.        \n");
13190         MrBayesPrint ("   Minpartfreq   -- The minimum probability of partitions to include in summary  \n");
13191         MrBayesPrint ("                    statistics.                                                  \n");
13192         MrBayesPrint ("   Contype       -- Type of consensus tree. 'Halfcompat' results in a 50%% major-\n");
13193         MrBayesPrint ("                    ity rule tree, 'Allcompat' adds all compatible groups to such\n");
13194         MrBayesPrint ("                    a tree.                                                      \n");
13195         MrBayesPrint ("   Conformat     -- Format of consensus tree. The 'Figtree' setting results in a \n");
13196         MrBayesPrint ("                    consensus tree formatted for the program FigTree, with rich  \n");
13197         MrBayesPrint ("                    summary statistics. The 'Simple' setting results in a simple \n");
13198         MrBayesPrint ("                    consensus tree written in a format read by a variety of pro- \n");
13199         MrBayesPrint ("                    grams.                                                       \n");
13200         MrBayesPrint ("   Outputname    -- Base name of the file(s) to which 'sumt' results will be     \n");
13201         MrBayesPrint ("                    printed. The default is the same as 'Filename'.              \n");
13202         MrBayesPrint ("   Calctreeprobs -- Determines whether tree probabilities should be calculated.  \n");
13203         MrBayesPrint ("   Showtreeprobs -- Determines whether tree probabilities should be displayed on \n");
13204         MrBayesPrint ("                    screen.                                                      \n");
13205         MrBayesPrint ("   Hpd           -- Determines whether credibility intervals will be given as the\n");
13206         MrBayesPrint ("                    region of Highest Posterior Density ('Yes') or as the inter- \n");
13207         MrBayesPrint ("                    val containing the median 95 %% of sampled values ('No').    \n");
13208         MrBayesPrint ("   Savebrparams  -- Set this option to 'yes' to save all sampled branch and node \n");
13209         MrBayesPrint ("                    parameter values to a separate file with the filename ending \n");
13210         MrBayesPrint ("                    in '.brparams'. All partitions with a posterior probability  \n");
13211         MrBayesPrint ("                    larger than Minbrparamfreq will be included.                 \n");
13212         MrBayesPrint ("   Minbrparamfreq -- The minimum probability of partitions for which to save     \n");
13213         MrBayesPrint ("                     parameter values to file if 'Savebrparams' is set to 'yes'. \n");
13214         MrBayesPrint ("                                                                                 \n");
13215         MrBayesPrint ("   Current settings:                                                             \n");
13216         MrBayesPrint ("                                                                                 \n");
13217         MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
13218         MrBayesPrint ("   --------------------------------------------------------                      \n");
13219         MrBayesPrint ("   Relburnin       Yes/No                   %s                                   \n", chainParams.relativeBurnin == YES ? "Yes" : "No");
13220         MrBayesPrint ("   Burnin          <number>                 %d                                   \n", chainParams.chainBurnIn);
13221         MrBayesPrint ("   Burninfrac      <number>                 %1.2lf                               \n", chainParams.burninFraction);
13222         MrBayesPrint ("   Nruns           <number>                 %d                                   \n", sumtParams.numRuns);
13223         MrBayesPrint ("   Ntrees          <number>                 %d                                   \n", sumtParams.numTrees);
13224         if (sumtParams.numRuns == 1 && sumtParams.numTrees == 1)
13225             MrBayesPrint ("   Filename        <name>                   %s<.t>\n", sumtParams.sumtFileName);
13226         else if (sumtParams.numRuns == 1 && sumtParams.numTrees > 1)
13227             MrBayesPrint ("   Filename        <name>                   %s<.tree<i>.t>\n", sumtParams.sumtFileName);
13228         else if (sumtParams.numRuns > 1 && sumtParams.numTrees == 1)
13229             MrBayesPrint ("   Filename        <name>                   %s<.run<i>.t>\n", sumtParams.sumtFileName);
13230         else if (sumtParams.numRuns > 1 && sumtParams.numTrees > 1)
13231             MrBayesPrint ("   Filename        <name>                   %s<.tree<i>.run<i>.t>\n", sumtParams.sumtFileName);
13232         MrBayesPrint ("   Minpartfreq     <number>                 %1.2lf                               \n", sumtParams.minPartFreq);
13233         MrBayesPrint ("   Contype         Halfcompat/Allcompat     %s\n", sumtParams.sumtConType);
13234         MrBayesPrint ("   Conformat       Figtree/Simple           %s                                   \n", sumtParams.consensusFormat == SIMPLE ? "Simple" : "Figtree");
13235         MrBayesPrint ("   Outputname      <name>                   %s<.parts etc>\n", sumtParams.sumtOutfile);
13236         MrBayesPrint ("   Calctreeprobs   Yes/No                   %s                                   \n", sumtParams.calcTreeprobs == YES ? "Yes" : "No");
13237         MrBayesPrint ("   Showtreeprobs   Yes/No                   %s                                   \n", sumtParams.showSumtTrees == YES ? "Yes" : "No");
13238         MrBayesPrint ("   Hpd             Yes/No                   %s                                   \n", sumtParams.HPD == YES ? "Yes" : "No");
13239         MrBayesPrint ("   Savebrparams    Yes/No                   %s                                   \n", sumtParams.saveBrParams == YES ? "Yes" : "No");
13240         MrBayesPrint ("   Minbrparamfreq  <number>                 %1.2lf                               \n", sumtParams.minBrParamFreq);
13241         MrBayesPrint ("                                                                                 \n");
13242         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13243         }
13244     else if (!strcmp(helpTkn, "Tree"))
13245         {
13246         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13247         MrBayesPrint ("   Tree                                                                          \n");
13248         MrBayesPrint ("                                                                                 \n");
13249         MrBayesPrint ("   This command is used by MrBayes to write trees to a nexus tree file. Trees    \n");
13250         MrBayesPrint ("   are written in the Newick format. For instance,                               \n");
13251         MrBayesPrint ("                                                                                 \n");
13252         MrBayesPrint ("      tree ((1,2),3,4);                                                          \n");
13253         MrBayesPrint ("                                                                                 \n");
13254         MrBayesPrint ("   describes an unrooted tree with taxa 1 and 2 being more closely related to    \n");
13255         MrBayesPrint ("   each other than to taxa 3 and 4. If branch lengths are saved to file, they    \n");
13256         MrBayesPrint ("   are given after a colon sign immediately following the terminal taxon or the  \n");
13257         MrBayesPrint ("   interior node they refer to. An example of an unrooted tree with branch       \n");
13258         MrBayesPrint ("   lengths is:                                                                   \n");
13259         MrBayesPrint ("                                                                                 \n");
13260         MrBayesPrint ("      tree ((1:0.064573,2:0.029042):0.041239,3:0.203988,4:0.187654);             \n");
13261         MrBayesPrint ("                                                                                 \n");
13262         MrBayesPrint ("   Trees that are rooted (clock trees) are written with a basal dichotomy        \n");
13263         MrBayesPrint ("   instead of a basal trichotomy. If the tree described above had been rooted    \n");
13264         MrBayesPrint ("   on the branch leading to taxon 4, it would have been represented as:          \n");
13265         MrBayesPrint ("                                                                                 \n");
13266         MrBayesPrint ("      tree (((1,2),3),4);                                                        \n");
13267         MrBayesPrint ("                                                                                 \n");
13268         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13269         }
13270     else if (!strcmp(helpTkn, "Report"))
13271         {
13272         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13273         MrBayesPrint ("   Report                                                                        \n");
13274         MrBayesPrint ("                                                                                 \n");
13275         MrBayesPrint ("   This command allows you to control how the posterior distribution is          \n");
13276         MrBayesPrint ("   reported. For rate parameters, it allows you to choose among several popular  \n");
13277         MrBayesPrint ("   parameterizations. The report command also allows you to request printing of  \n");
13278         MrBayesPrint ("   some model aspects that are usually not reported. For instance, if a node is  \n");
13279         MrBayesPrint ("   constrained in the analysis, MrBayes can print the probabilities of the       \n");
13280         MrBayesPrint ("   ancestral states at that node. Similarly, if there is rate variation in the   \n");
13281         MrBayesPrint ("   model, MrBayes can print the inferred site rates, and if there is omega varia-\n");
13282         MrBayesPrint ("   tion, MrBayes can print the inferred omega (positive selection) values for    \n");
13283         MrBayesPrint ("   each codon. In a complex model with several partitions, each partition is     \n");
13284         MrBayesPrint ("   controlled separately using the same 'Applyto' mechanism as in the 'Lset' and \n");
13285         MrBayesPrint ("   'Prset' commands.                                                             \n");
13286         MrBayesPrint ("                                                                                 \n");
13287         MrBayesPrint ("   Options:                                                                      \n");
13288         MrBayesPrint ("                                                                                 \n");
13289         MrBayesPrint ("   Applyto   -- This option allows you to apply the report commands to specific  \n");
13290         MrBayesPrint ("                partitions. This command should be the first in the list of      \n");
13291         MrBayesPrint ("                commands specified in 'report'.                                  \n");
13292         MrBayesPrint ("                For example,                                                     \n");
13293         MrBayesPrint ("                                                                                 \n");
13294         MrBayesPrint ("                   report applyto=(1,2) tratio=ratio                             \n");
13295         MrBayesPrint ("                                                                                 \n");
13296         MrBayesPrint ("                   report applyto=(3) tratio=dirichlet                           \n");
13297         MrBayesPrint ("                                                                                 \n");
13298         MrBayesPrint ("                would result in the transition and transversion rates of the     \n");
13299         MrBayesPrint ("                first and second partitions in the model being reported as a     \n");
13300         MrBayesPrint ("                ratio and the transition and transversion rates of the third     \n");
13301         MrBayesPrint ("                partition being reported as proportions of the rate sum (the     \n");
13302         MrBayesPrint ("                Dirichlet parameterization).                                     \n");
13303         MrBayesPrint ("   Tratio    -- This specifies the report format for the transition and trans-   \n");
13304         MrBayesPrint ("                version rates of a nucleotide substitution model with nst=2.     \n");
13305         MrBayesPrint ("                If 'ratio' is selected, the rates will be reported as a ratio    \n");
13306         MrBayesPrint ("                (transition rate/transversion rate). If 'dirichlet' is selected, \n");
13307         MrBayesPrint ("                the transition and transversion rates will instead be reported   \n");
13308         MrBayesPrint ("                as proportions of the rate sum. For example, if the transition   \n");
13309         MrBayesPrint ("                rate is three times the transversion rate and 'ratio' is selec-  \n");
13310         MrBayesPrint ("                ted, this will reported as a single value, '3.0'. If 'dirichlet' \n");
13311         MrBayesPrint ("                is selected instead, the same rates will be reported using two   \n");
13312         MrBayesPrint ("                values, '0.75 0.25'. The sum of the Dirichlet values is always 1.\n");
13313         MrBayesPrint ("                Although the Dirichlet format may be unfamiliar to some users,   \n");
13314         MrBayesPrint ("                it is more convenient for specifying priors than the ratio       \n");
13315         MrBayesPrint ("                format.                                                          \n");
13316         MrBayesPrint ("   Revmat    -- This specifies the report format for the substitution rates of   \n");
13317         MrBayesPrint ("                a GTR substitution model for nucleotide or amino acid data. If   \n");
13318         MrBayesPrint ("                'ratio' is selected, the rates will be reported scaled to the    \n");
13319         MrBayesPrint ("                G-T rate (for nucleotides) or the Y-V rate (for amino acids). If \n");
13320         MrBayesPrint ("                'dirichlet' is specified instead, the rates are reported as pro- \n");
13321         MrBayesPrint ("                portions of the rate sum. For instance, assume that the C-T rate \n");
13322         MrBayesPrint ("                is twice the A-G rate and four times the transversion rates,     \n");
13323         MrBayesPrint ("                which are equal. If the report format is set to 'ratio', this    \n");
13324         MrBayesPrint ("                would be reported as '1.0 2.0 1.0 1.0 4.0 1.0' since the rates   \n");
13325         MrBayesPrint ("                are reported in the order rAC, rAG, rAT, rCG, rCT, rGT and scaled\n");
13326         MrBayesPrint ("                relative to the last rate, the G-T rate. If 'dirichlet' is selec-\n");
13327         MrBayesPrint ("                ted instead, the same rates would have been reported as '0.1 0.2 \n");
13328         MrBayesPrint ("                0.1 0.1 0.4 0.1' since the rates are now scaled so that they sum \n");
13329         MrBayesPrint ("                to 1.0. The Dirichlet format is the parameterization used for    \n");
13330         MrBayesPrint ("                formulating priors on the rates.                                 \n");
13331         MrBayesPrint ("   Ratemult  -- This specifies the report format used for the rate multiplier of \n");
13332         MrBayesPrint ("                different model partitions. Three formats are available. If      \n");
13333         MrBayesPrint ("                'scaled' is selected, then rates are scaled such that the mean   \n");
13334         MrBayesPrint ("                rate per site across partitions is 1.0. If 'ratio' is chosen,    \n");
13335         MrBayesPrint ("                the rates are scaled relative to the rate of the first parti-    \n");
13336         MrBayesPrint ("                tion. Finally, if 'dirichlet' is chosen, the rates are given as  \n");
13337         MrBayesPrint ("                proportions of the rate sum. The latter is the format used       \n");
13338         MrBayesPrint ("                when formulating priors on the rate multiplier.                  \n");
13339         MrBayesPrint ("   Tree      -- This specifies the report format used for the tree(s). Two op-   \n");
13340         MrBayesPrint ("                tions are available. 'Topology' results in only the topology     \n");
13341         MrBayesPrint ("                being printed to file, whereas 'brlens' causes branch lengths to \n");
13342         MrBayesPrint ("                to be printed as well.                                           \n");
13343         MrBayesPrint ("   Ancstates -- If this option is set to 'yes', MrBayes will print the pro-      \n");
13344         MrBayesPrint ("                bability of the ancestral states at all constrained nodes. Typ-  \n");
13345         MrBayesPrint ("                ically, you are interested in the ancestral states of only a few \n");
13346         MrBayesPrint ("                characters and only at one node in the tree. To perform such     \n");
13347         MrBayesPrint ("                an analysis, first define and enforce a topology constraint      \n");
13348         MrBayesPrint ("                using 'constraint' and 'prset topologypr = constraints (...)'.   \n");
13349         MrBayesPrint ("                Then put the character(s) of interest in a separate partition and\n");
13350         MrBayesPrint ("                set MrBayes to report the ancestral states for that partition.   \n");
13351         MrBayesPrint ("                For instance, if the characters of interest are in partition 2,  \n");
13352         MrBayesPrint ("                use 'report applyto=(2) ancstates=yes' to force MrBayes to print \n");
13353         MrBayesPrint ("                the probability of the ancestral states of those characters at   \n");
13354         MrBayesPrint ("                the constrained node to the '.p' file.                           \n");
13355         MrBayesPrint ("   Siterates -- If this option is set to 'yes' and the relevant model has rate   \n");
13356         MrBayesPrint ("                variation across sites, then the site rates, weighted over rate  \n");
13357         MrBayesPrint ("                categories, will be reported to the '.p' file.                   \n");
13358         MrBayesPrint ("   Possel    -- If this option is set to 'yes' and the relevant model has omega  \n");
13359         MrBayesPrint ("                variation across sites, the probability that each model site     \n");
13360         MrBayesPrint ("                (codon in this case) is positively selected will be written to   \n");
13361         MrBayesPrint ("                file.                                                            \n");
13362         MrBayesPrint ("   Siteomega -- If this option is set to 'yes' and the relevant model has omega  \n");
13363         MrBayesPrint ("                variation across sites, the weighted omega value (over omega     \n");
13364         MrBayesPrint ("                categories) for each model site will be reported to file.        \n");
13365         MrBayesPrint ("                                                                                 \n");
13366         if (numCurrentDivisions == 0)
13367             tempInt = 1;
13368         else
13369             tempInt = numCurrentDivisions;
13370         for (i=0; i<tempInt; i++)
13371             {
13372             if (numCurrentDivisions == 0)
13373                 {
13374                 MrBayesPrint ("   Default report settings:                                                       \n");
13375                 mp = &defaultModel;
13376                 }
13377             else
13378                 {
13379                 MrBayesPrint ("   Current report settings for partition %d:                                              \n", i+1);
13380                 mp = &modelParams[i];
13381                 }
13382             MrBayesPrint ("                                                                                 \n");
13383             MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
13384             MrBayesPrint ("   --------------------------------------------------------                      \n");
13385             MrBayesPrint ("   Tratio          Ratio/Dirichlet          %s                                   \n", mp->tratioFormat);
13386             MrBayesPrint ("   Revmat          Ratio/Dirichlet          %s                                   \n", mp->revmatFormat);
13387             MrBayesPrint ("   Ratemult        Scaled/Ratio/Dirichlet   %s                                   \n", mp->ratemultFormat);
13388             MrBayesPrint ("   Tree            Brlens/Topology          %s                                   \n", mp->treeFormat);
13389             MrBayesPrint ("   Ancstates       Yes/No                   %s                                   \n", mp->inferAncStates);
13390             MrBayesPrint ("   Siterates       Yes/No                   %s                                   \n", mp->inferSiteRates);
13391             MrBayesPrint ("   Possel          Yes/No                   %s                                   \n", mp->inferPosSel);
13392             MrBayesPrint ("   Siteomega       Yes/No                   %s                                   \n", mp->inferSiteOmegas);
13393             MrBayesPrint ("                                                                                 \n");
13394             MrBayesPrint ("   ------------------------------------------------------------------            \n");
13395             }
13396         }
13397     else if (!strcmp(helpTkn, "Manual"))
13398         {
13399         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13400         MrBayesPrint ("   Manual                                                                        \n");
13401         MrBayesPrint ("                                                                                 \n");
13402         MrBayesPrint ("   This command allows you to generate a text file containing help information   \n");
13403         MrBayesPrint ("   on all the available commands. This text file can be used as an up-to-date    \n");
13404         MrBayesPrint ("   command reference. You can set the name of the text file using the            \n");
13405         MrBayesPrint ("   \"filename\" option; the default is \"commref_mb<version>.txt\".              \n");
13406         MrBayesPrint ("                                                                                 \n");
13407         MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
13408         MrBayesPrint ("   --------------------------------------------------------                      \n");
13409         MrBayesPrint ("   Filename        <name>                   %s                                   \n", manFileName);
13410         MrBayesPrint ("                                                                                 \n");
13411         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13412         }
13413     else if (!strcmp(helpTkn, "Showmoves"))
13414         {
13415         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13416         MrBayesPrint ("   Showmoves                                                                     \n");
13417         MrBayesPrint ("                                                                                 \n");
13418         MrBayesPrint ("   This command shows the MCMC samplers (moves) that are switched on for the     \n");
13419         MrBayesPrint ("   parameters in the current model. The basic usage is                           \n");
13420         MrBayesPrint ("                                                                                 \n");
13421         MrBayesPrint ("      showmoves                                                                  \n");
13422         MrBayesPrint ("                                                                                 \n");
13423         MrBayesPrint ("   If you want to see all available moves, use                                   \n");
13424         MrBayesPrint ("                                                                                 \n");
13425         MrBayesPrint ("      showmoves allavailable=yes                                                 \n");
13426         MrBayesPrint ("                                                                                 \n");
13427         MrBayesPrint ("   If you want to change any of the tuning parameters for the moves, use the     \n");
13428         MrBayesPrint ("   'propset' command.                                                            \n");
13429         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13430         }
13431     else if (!strcmp(helpTkn, "Showparams"))
13432         {
13433         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13434         MrBayesPrint ("   Showparams                                                                    \n");
13435         MrBayesPrint ("                                                                                 \n");
13436         MrBayesPrint ("   This command shows all of the parameters in the current model. The basic      \n");
13437         MrBayesPrint ("   usage is                                                                      \n");
13438         MrBayesPrint ("                                                                                 \n");
13439         MrBayesPrint ("      showparams                                                                 \n");
13440         MrBayesPrint ("                                                                                 \n");
13441         MrBayesPrint ("   The parameters are listed together with their priors, the available moves,    \n");
13442         MrBayesPrint ("   and the current value(s), which will be used as the starting values in the    \n");
13443         MrBayesPrint ("   next mcmc analysis.                                                           \n");
13444         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13445         }
13446     else if (!strcmp(helpTkn, "Startvals"))
13447         {
13448         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13449         MrBayesPrint ("   Startvals                                                                     \n");
13450         MrBayesPrint ("                                                                                 \n");
13451         MrBayesPrint ("   Use this command to change the current values for parameters in your model.   \n");
13452         MrBayesPrint ("   These values will be used as the starting values in the next mcmc analysis.   \n");
13453         MrBayesPrint ("   The basic format is:                                                          \n");
13454         MrBayesPrint ("                                                                                 \n");
13455         MrBayesPrint ("      startvals <param>=(<value_1>,<value_2>,...,<value_n>)                      \n");
13456         MrBayesPrint ("                                                                                 \n");
13457         MrBayesPrint ("   for all substitution model parameters. The format is slightly different for   \n");
13458         MrBayesPrint ("   parameters that are written to a tree file:                                   \n");
13459         MrBayesPrint ("                                                                                 \n");
13460         MrBayesPrint ("      startvals <param>=<tree_name>                                              \n");
13461         MrBayesPrint ("                                                                                 \n");
13462         MrBayesPrint ("   This version of the command will look for a tree with the specified name      \n");
13463         MrBayesPrint ("   among the trees read in previously when parsing a tree block. The information \n");
13464         MrBayesPrint ("   stored in that tree will be used to set the starting value of the parameter.  \n");
13465         MrBayesPrint ("   The parameters that are set using this mechanism include topology and branch  \n");
13466         MrBayesPrint ("   length parameters, as well as relaxed clock branch rates, cpp events and      \n");
13467         MrBayesPrint ("   cpp branch rate multipliers.                                                  \n");
13468         MrBayesPrint ("                                                                                 \n");
13469         MrBayesPrint ("   The above versions of the command will set the value for all runs and chains. \n");
13470         MrBayesPrint ("   You can also set the value for an individual run and chain by using the format\n");
13471         MrBayesPrint ("                                                                                 \n");
13472         MrBayesPrint ("      startvals <param>(<run>,<chain>)=(<value_1>,...)                           \n");
13473         MrBayesPrint ("                                                                                 \n");
13474         MrBayesPrint ("   where <run> is the index of the run and <chain> the index of the chain. If    \n");
13475         MrBayesPrint ("   the run index is omitted, the values will be changed for all runs. Similarly, \n");
13476         MrBayesPrint ("   if the chain index is omitted, all chains will be set to the specified value. \n");
13477         MrBayesPrint ("   For example, if we wanted to set the values of the stationary frequency       \n");
13478         MrBayesPrint ("   parameter pi{1} to (0.1,0.1,0.4,0.4) for all chains in run 1, and to          \n");
13479         MrBayesPrint ("   (0.3,0.3,0.2,0.2) for chain 3 of run 2, we would use                          \n");
13480         MrBayesPrint ("                                                                                 \n");
13481         MrBayesPrint ("      startvals pi{1}(1,)=(0.1,0.1,0.4,0.4) pi{1}(2,3)=(0.3,0.3,0.2,0.2)         \n");
13482         MrBayesPrint ("                                                                                 \n");
13483         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13484         }
13485     else
13486         {
13487         return (ERROR);
13488         }
13489 
13490     return (NO_ERROR);
13491 }
13492 
13493 
13494 /* IsAmbig: This function returns YES if character is set as ambiguous
13495    either by using parenthetic notation or by ambiguity codes. It returns
13496    NO if character is unambiguous, missing or gapped */
IsAmbig(int charCode,int dType)13497 int IsAmbig (int charCode, int dType)
13498 {
13499     if (dType == DNA || dType == RNA || dType == STANDARD || dType == RESTRICTION || dType == PROTEIN)
13500         {
13501         if (charCode != MISSING && charCode != GAP)
13502             if (NBits(charCode) > 1)
13503                 return (YES);
13504         }
13505     else if (dType == CONTINUOUS)
13506         {
13507         /* do nothing, these cannot be partly ambiguous */
13508         }
13509     else
13510         {
13511         MrBayesPrint ("Unknown datatype in \"IsAmbig\"\n", spacer);
13512         }
13513 
13514     return (NO);
13515 }
13516 
13517 
IsArgValid(char * tk,char * validArg)13518 int IsArgValid (char *tk, char *validArg)
13519 {
13520     int         i, j, k, tkLen, targetLen, numDiff, numStrMatches;
13521     char        tempStr[100];
13522     ParmInfoPtr p;
13523 
13524     p = paramPtr;
13525     tkLen = (int) strlen(tk);
13526 
13527     numStrMatches = i = j = 0;
13528     do
13529         {
13530         if (p->valueList[i] == '|' || p->valueList[i] == '\0')
13531             {
13532             tempStr[j++] = '\0';
13533             targetLen = (int) strlen(tempStr);
13534             if (tkLen <= targetLen)
13535                 {
13536                 numDiff = 0;
13537                 for (k=0; k<tkLen; k++)
13538                     if (ChangeCase(tk[k]) != ChangeCase(tempStr[k]))
13539                         numDiff++;
13540                 if (numDiff == 0)
13541                     {
13542                     numStrMatches++;
13543                     strcpy (validArg, tempStr);
13544                     }
13545                 }
13546             j = 0;
13547             }
13548         else
13549             tempStr[j++] = p->valueList[i];
13550         i++;
13551         }
13552     while (p->valueList[i] != '\0');
13553 
13554     if (numStrMatches == 0)
13555         {
13556         MrBayesPrint ("%s   No valid match for argument \"%s\"\n", spacer, tk);
13557         return (ERROR);
13558         }
13559     else if (numStrMatches == 1)
13560         {
13561         return (NO_ERROR);
13562         }
13563     else
13564         {
13565         MrBayesPrint ("%s   Argument \"%s\" is ambiguous\n", spacer, tk);
13566         return (ERROR);
13567         }
13568 }
13569 
13570 
IsIn(char ch,char * s)13571 int IsIn (char ch, char *s)
13572 {
13573     while (*s)
13574         {
13575         if (*s++ == ch)
13576             return 1;
13577         }
13578     return 0;
13579 }
13580 
13581 
IsMissing(int charCode,int dType)13582 int IsMissing (int charCode, int dType)
13583 {
13584     if (dType == DNA || dType == RNA)
13585         {
13586         if (charCode == 15 || charCode == 16)
13587             return (YES);
13588         }
13589     else if (dType == STANDARD || dType == PROTEIN)
13590         {
13591         if (charCode == MISSING || charCode == GAP)
13592             return (YES);
13593         }
13594     else if (dType == RESTRICTION)
13595         {
13596         if (charCode == 3 || charCode == 4)
13597             return (YES);
13598         }
13599     else if (dType == CONTINUOUS)
13600         {
13601 
13602         }
13603     else
13604         {
13605         MrBayesPrint ("Unknown datatype in \"IsMissing\"\n", spacer);
13606         }
13607     return (NO);
13608 }
13609 
13610 
IsSame(char * s1,char * s2)13611 int IsSame (char *s1, char *s2)
13612 {
13613     int         i, nDiff, isIdentical, len;
13614 
13615     isIdentical = YES;
13616     if (strlen(s1) != strlen(s2))
13617         isIdentical = NO; /* strings cannot be identical because they are different lengths */
13618 
13619     /* now, we go through both strings, one character at a time, to see if
13620        any are different */
13621     if (strlen(s1) > strlen(s2))
13622         len = (int) strlen(s2);
13623     else
13624         len = (int) strlen(s1);
13625     i = nDiff = 0;
13626     while (i < len)
13627         {
13628         if (tolower(s1[i]) != tolower(s2[i]))
13629             nDiff++;
13630         i++;
13631         }
13632     if (nDiff == 0 && isIdentical == YES)
13633         return (SAME);
13634     else if (nDiff == 0 && isIdentical == NO)
13635         return (CONSISTENT_WITH);
13636     else
13637         return (DIFFERENT);
13638 }
13639 
13640 
IsWhite(char c)13641 int IsWhite (char c)
13642 {
13643     if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
13644         {
13645         if (c == '\n' || c == '\r')
13646             return 2;
13647         return 1;
13648         }
13649     return 0;
13650 }
13651 
13652 
NucID(char nuc)13653 int NucID (char nuc)
13654 {
13655     char        n;
13656 
13657     if (nuc == 'U' || nuc == 'u')
13658         n = 'T';
13659     else
13660         n = nuc;
13661 
13662     if (n == 'A' || n == 'a')
13663         {
13664         return 1;
13665         }
13666     else if (n == 'C' || n == 'c')
13667         {
13668         return 2;
13669         }
13670     else if (n == 'G' || n == 'g')
13671         {
13672         return 4;
13673         }
13674     else if (n == 'T' || n == 't')
13675         {
13676         return 8;
13677         }
13678     else if (n == 'R' || n == 'r')
13679         {
13680         return 5;
13681         }
13682     else if (n == 'Y' || n == 'y')
13683         {
13684         return 10;
13685         }
13686     else if (n == 'M' || n == 'm')
13687         {
13688         return 3;
13689         }
13690     else if (n == 'K' || n == 'k')
13691         {
13692         return 12;
13693         }
13694     else if (n == 'S' || n == 's')
13695         {
13696         return 6;
13697         }
13698     else if (n == 'W' || n == 'w')
13699         {
13700         return 9;
13701         }
13702     else if (n == 'H' || n == 'h')
13703         {
13704         return 11;
13705         }
13706     else if (n == 'B' || n == 'b')
13707         {
13708         return 14;
13709         }
13710     else if (n == 'V' || n == 'v')
13711         {
13712         return 7;
13713         }
13714     else if (n == 'D' || n == 'd')
13715         {
13716         return 13;
13717         }
13718     else if (n == 'N' || n == 'n')
13719         {
13720         return 15;
13721         }
13722     else if (n == gapId)
13723         {
13724         return GAP;
13725         }
13726     else if (n == missingId)
13727         {
13728         return MISSING;
13729         }
13730     else
13731         return -1;
13732 }
13733 
13734 
13735 /*-------| ParseCommand |------------------------------------------------
13736 |
13737 |   This function is used to parse a file. The expected format is:
13738 |
13739 |      command parameter=value parameter=value ... ;
13740 |
13741 |   For example, the following is a valid line for this parser:
13742 |
13743 |      lset nst=2;
13744 |
13745 |   In some cases, however, the format is:
13746 |
13747 |      command stuff more stuff ... ;
13748 |
13749 |   For example, when reading a data file, the matrix command might be:
13750 |
13751 |      matrix
13752 |         taxon_1 data
13753 |         taxon_2 data
13754 |         taxon_3 data
13755 |         ;
13756 |
13757 |   Like before, the command and all of the stuff for that command are
13758 |   terminated by a semicolon.
13759 |
13760 */
ParseCommand(char * s)13761 int ParseCommand (char *s)
13762 {
13763     int             rc, tokenType, inError, numMatches, skipCmd;
13764     char            errStr[100];
13765 
13766     numMatches = 0;     /* Avoid gcc warnings (actually set in call to FindValidCommand) */
13767     cmdStr = s;
13768     tokenP = &s[0];
13769 
13770 #   if defined (ECHO_PROCESSED_COMMANDS)
13771         MrBayesPrint ("Currently processing command: %s\n", s);
13772 #   endif
13773 
13774     inError = skipCmd = NO;
13775     do
13776         {
13777         /* Get the next token. A token is a valid word in a line. Token type is defined in "bayes.h". */
13778         if (GetToken (token, &tokenType, &tokenP))
13779             {
13780             inError = YES;
13781             break;
13782             }
13783         if (strlen(token) > 0 || tokenType == ALPHA)
13784             {
13785 #           if defined (SHOW_TOKENS)
13786             MrBayesPrint ("%s\n", token);
13787 #           endif
13788             if (tokenType == LEFTCOMMENT)
13789                 {
13790                 /* If the token is a left comment "[", then we don't want to
13791                    actually process commands until we find a right comment.  */
13792                 /* The exception is if readComment is set to YES, in which case
13793                    we will leave it to the parser functions to decide on whether
13794                    they want to read the comment or not */
13795                 if (readComment == NO || inComment == YES)
13796                     {
13797                     inComment = YES;
13798                     numComments++;
13799                     }
13800                 }
13801             if (inComment == NO && inForeignBlock == NO)
13802                 {
13803                 if (tokenType != SEMICOLON)
13804                     {
13805                     /* If the token is not a semicolon, then we will be processing
13806                        either a command or a parameter. */
13807                     if (expecting == Expecting(COMMAND))
13808                         {
13809                         /* We are expecting to find a command (defined above in "commands[]"). Find the
13810                            correct command and set a pointer to that command. */
13811                         commandPtr = NULL;
13812                         if (FindValidCommand (token, &numMatches) == ERROR)
13813                             {
13814                             /* We couldn't find the command or the user did not specify enough letters
13815                                to unambiguously determine the command. The command pointer (commandPtr)
13816                                is NULL. */
13817                             if (numMatches == 0)
13818                                 MrBayesPrint ("%s   Could not find command \"%s\"\n", spacer, token);
13819                             else
13820                                 MrBayesPrint ("%s   Ambiguous command \"%s\"\n", spacer, token);
13821                             inError = YES;
13822                             }
13823                         else
13824                             {
13825                             /* We did find a valid command. Set what we are expecting to see next. */
13826                             expecting = commandPtr->expect;
13827 
13828                             /* Check to see if we have one of the so-called special cases in which a
13829                                command is not necessarily followed by a parameter (e.g., matrix). If we
13830                                do have a special case, then we want to set the parameter pointer (paramPtr)
13831                                appropriately. In this case, simply go to the first parameter in the parmList. */
13832                             if (commandPtr->specialCmd == YES)
13833                                 {
13834                                 isFirstMatrixRead = YES;
13835                                 foundFirst = NO;
13836                                 paramPtr = paramTable + commandPtr->parmList[0];
13837                                 }
13838                             if (strcmp(commandPtr->string, "Execute")==0)
13839                                 {
13840                                 /* set the tokenizer to recognize quoted strings */
13841                                 readWord = YES;
13842                                 }
13843                             }
13844                         }
13845                     else
13846                         {
13847                         /* We are expecting to find a parameter or a value for the parameter, not a command. */
13848                         if ((expecting & Expecting(PARAMETER)) == Expecting(PARAMETER) &&
13849                             (expecting & Expecting(tokenType)) != Expecting(tokenType))
13850                             {
13851                             /* Specifically, if we are here, we need to go through the parameter list,
13852                                checking to see if the token is a valid parameter. */
13853                             expecting = (expecting & Expecting(PARAMETER));
13854                             if (FindValidParam (token, &numMatches) == ERROR)
13855                                 {
13856                                 /* The token is not a valid parameter. */
13857                                 if (numMatches == 0)
13858                                     MrBayesPrint ("%s   Could not find parameter \"%s\"\n", spacer, token);
13859                                 else
13860                                     MrBayesPrint ("%s   Ambiguous parameter \"%s\"\n", spacer, token);
13861                                 inError = YES;
13862                                 }
13863                             else
13864                                 {
13865                                 /* The token is a valid parameter. Call the appropriate function ("DoXxxxParm"). */
13866                                 if ((paramPtr->fp)(paramPtr->string, token) == ERROR)
13867                                     {
13868                                     if (strcmp("Xxxxxxxxxx", paramPtr->string))
13869                                         MrBayesPrint ("%s   Error when setting parameter \"%s\" (1)\n", spacer, paramPtr->string);
13870                                     inError = YES;
13871                                     }
13872                                 }
13873                             }
13874                         else
13875                             {
13876                             /* Otherwise, we are expecting a value for the parameter. Call the appropriate function ("DoXxxxParm"). */
13877                             if ((expecting & Expecting(tokenType)) != 0)
13878                                 expecting = (expecting & Expecting(tokenType));
13879                             if ((Expecting(tokenType) & expecting) == Expecting(tokenType))
13880                                 {
13881                                 if ((paramPtr->fp)(paramPtr->string, token) == ERROR)
13882                                     {
13883                                     if (strcmp("Xxxxxxxxxx", paramPtr->string))
13884                                         MrBayesPrint ("%s   Error when setting parameter \"%s\" (2)\n", spacer, paramPtr->string);
13885                                     inError = YES;
13886                                     }
13887                                 }
13888                             else
13889                                 {
13890                                 inError = YES;
13891                                 WhatVariableExp (expecting, errStr);
13892                                 MrBayesPrint ("%s   Expecting '%s'\n", spacer, errStr+1);  /* there will be an initial space in errStr so print from pos 1 */
13893                                 if (numOpenExeFiles > 0)
13894                                     MrBayesPrint ("%s   Instead found '%s' in command '%s'\n",
13895                                         spacer, token, commandPtr->string);
13896                                 else
13897                                     MrBayesPrint ("%s   Instead found '%s' in command '%s' at position %d\n",
13898                                         spacer, token, commandPtr->string, tokenP - cmdStr - strlen(token)+1);
13899                                 }
13900                             }
13901                         }
13902                     }
13903                 else
13904                     {
13905                     /* The token is a semicolon. This means that we are at the end of processing one command. We
13906                        need to clean things up. We do this by calling the finishing function ("DoXxxx"). */
13907                     if ((Expecting(SEMICOLON) & expecting) == Expecting(SEMICOLON))
13908                         {
13909                         if (commandPtr->cmdFxnPtr != NULL)
13910                             {
13911                             /* Finish up the command here. */
13912                             rc = (commandPtr->cmdFxnPtr) ();
13913                             if (rc  == ERROR || rc == ABORT)
13914                                 {
13915                                 if (rc == ABORT)
13916                                     {
13917                                     MrBayesPrint ("   Mcmc run aborted\n");
13918                                     }
13919                                 else if (rc == SKIP_COMMAND)
13920                                     {
13921                                     MrBayesPrint ("   Cancelled execution of command\n");
13922                                     skipCmd = YES;
13923                                     }
13924                                 else
13925                                     {
13926                                     MrBayesPrint ("%s   Error in command \"%s\"\n", spacer, commandPtr->string);
13927                                     inError = YES;
13928                                     }
13929                                 }
13930                             }
13931                         /* if the user typed "quit", then we want to bail out of this loop, with a NO_ERROR_QUIT */
13932                         if (!strcmp(commandPtr->string, "Quit"))
13933                             return (NO_ERROR_QUIT);
13934                         expecting = Expecting(COMMAND);
13935                         }
13936                     else
13937                         {
13938                         inError = YES;
13939                         WhatVariableExp (expecting, errStr);
13940                         MrBayesPrint ("%s   Expecting %s\n", spacer, errStr);
13941                         }
13942                     }
13943                 }
13944             /* Check to see if a comment is terminated. A comment can either be a right comment "]" or, if we were in a foreign nexus block
13945                (e.g., a "paup" block) the terminating comment will be "end". */
13946             if (tokenType == RIGHTCOMMENT)
13947                 {
13948                 if (inComment == NO && readComment == NO)
13949                     {
13950                     MrBayesPrint ("%s   Found \"]\", without having previously found \"[\"\n", spacer);
13951                     inError = YES;
13952                     }
13953                 else if (inComment == NO && readComment == YES)
13954                     {
13955                     /* This is OK, we just pass through and rely on the command to handle the RIGHTCOMMENT */
13956                     }
13957                 else
13958                     {
13959                     numComments--;
13960                     if (numComments == 0)
13961                         inComment = NO;
13962                     }
13963                 }
13964             if ((IsSame(token, "end") == SAME || IsSame(token, "endblock") == SAME) && inForeignBlock == YES)
13965                 {
13966                 strcpy (spacer, "");
13967                 inForeignBlock = NO;
13968                 }
13969             }
13970 
13971         } while ((*token || tokenType == ALPHA) && inError == NO && skipCmd == NO);
13972 
13973     if (inError == YES)
13974         {
13975         readComment = NO;   /* reset this in case it is set to YES in command and we get an error exit */
13976         return (ERROR);
13977         }
13978     else
13979         return (NO_ERROR);
13980 }
13981 
13982 
PrintSettings(char * command)13983 void PrintSettings (char *command)
13984 {
13985     char yesNoStr[20];
13986 
13987     if (!strcmp(command,"Mcmc"))
13988         {
13989         MrBayesPrint ("   Parameter       Options               Current Setting                         \n");
13990         MrBayesPrint ("   -----------------------------------------------------                         \n");
13991         MrBayesPrint ("   Ngen            <number>              %d                                      \n", chainParams.numGen);
13992         MrBayesPrint ("   Nruns           <number>              %d                                      \n", chainParams.numRuns);
13993         MrBayesPrint ("   Nchains         <number>              %d                                      \n", chainParams.numChains);
13994         MrBayesPrint ("   Temp            <number>              %lf                                     \n", chainParams.chainTemp);
13995         MrBayesPrint ("   Reweight        <number>,<number>     %1.2lf v %1.2lf ^                       \n", chainParams.weightScheme[0], chainParams.weightScheme[1]);
13996         MrBayesPrint ("   Swapfreq        <number>              %d                                      \n", chainParams.swapFreq);
13997         MrBayesPrint ("   Nswaps          <number>              %d                                      \n", chainParams.numSwaps);
13998         MrBayesPrint ("   Samplefreq      <number>              %d                                      \n", chainParams.sampleFreq);
13999         MrBayesPrint ("   Printfreq       <number>              %d                                      \n", chainParams.printFreq);
14000         PrintYesNo (chainParams.printAll, yesNoStr);
14001         MrBayesPrint ("   Printall        Yes/No                %s                                      \n", yesNoStr);
14002         MrBayesPrint ("   Printmax        <number>              %d                                      \n", chainParams.printMax);
14003         PrintYesNo (chainParams.mcmcDiagn, yesNoStr);
14004         MrBayesPrint ("   Mcmcdiagn       Yes/No                %s                                      \n", yesNoStr);
14005         MrBayesPrint ("   Diagnfreq       <number>              %d                                      \n", chainParams.diagnFreq);
14006         if (chainParams.diagnStat == AVGSTDDEV)
14007             strcpy (yesNoStr, "Avgstddev");
14008         else
14009             strcpy (yesNoStr, "Maxstddev");
14010         MrBayesPrint ("   Diagnstat       Avgstddev/Maxstddev   %s                                     \n", yesNoStr);
14011         MrBayesPrint ("   Minpartfreq     <number>              %1.2lf                                 \n", chainParams.minPartFreq);
14012         PrintYesNo (chainParams.allChains, yesNoStr);
14013         MrBayesPrint ("   Allchains       Yes/No                %s                                     \n", yesNoStr);
14014         PrintYesNo (chainParams.allComps, yesNoStr);
14015         MrBayesPrint ("   Allcomps        Yes/No                %s                                     \n", yesNoStr);
14016         PrintYesNo (chainParams.relativeBurnin, yesNoStr);
14017         MrBayesPrint ("   Relburnin       Yes/No                %s                                     \n", yesNoStr);
14018         MrBayesPrint ("   Burnin          <number>              %d                                     \n", chainParams.chainBurnIn);
14019         MrBayesPrint ("   Burninfrac      <number>              %1.2lf                                 \n", chainParams.burninFraction);
14020         PrintYesNo (chainParams.stopRule, yesNoStr);
14021         MrBayesPrint ("   Stoprule        Yes/No                %s                                     \n", yesNoStr);
14022         MrBayesPrint ("   Stopval         <number>              %1.2lf                                 \n", chainParams.stopVal);
14023         PrintYesNo (chainParams.saveTrees, yesNoStr);
14024         MrBayesPrint ("   Savetrees       Yes/No                %s                                     \n", yesNoStr);
14025         PrintYesNo (chainParams.checkPoint, yesNoStr);
14026         MrBayesPrint ("   Checkpoint      Yes/No                %s                                     \n", yesNoStr);
14027         MrBayesPrint ("   Checkfreq       <number>              %d                                     \n", chainParams.checkFreq);
14028         MrBayesPrint ("   Filename        <name>                %s.<p/t>\n", chainParams.chainFileName);
14029         MrBayesPrint ("   Startparams     Current/Reset         %s                                     \n", chainParams.startParams);
14030         MrBayesPrint ("   Starttree       Current/Random/       %s                                     \n", chainParams.startTree);
14031         MrBayesPrint ("                   Parsimony                                                    \n");
14032         MrBayesPrint ("   Nperts          <number>              %d                                     \n", chainParams.numStartPerts);
14033         PrintYesNo (chainParams.runWithData, yesNoStr);
14034         MrBayesPrint ("   Data            Yes/No                %s                                     \n", yesNoStr);
14035         MrBayesPrint ("   Ordertaxa       Yes/No                %s                                     \n", chainParams.orderTaxa == YES? "Yes" : "No");
14036         MrBayesPrint ("   Append          Yes/No                %s                                     \n", chainParams.append == YES? "Yes" : "No");
14037         MrBayesPrint ("   Autotune        Yes/No                %s                                     \n", chainParams.autotune == YES? "Yes" : "No");
14038         MrBayesPrint ("   Tunefreq        <number>              %d                                     \n", chainParams.tuneFreq);
14039         MrBayesPrint ("                                                                                \n");
14040         }
14041 }
14042 
14043 
PrintYesNo(int yn,char s[4])14044 void PrintYesNo (int yn, char s[4])
14045 {
14046     if (yn == YES)
14047         strcpy (s, "Yes");
14048     else
14049         strcpy (s, "No");
14050 }
14051 
14052 
ProtID(char aa)14053 int ProtID (char aa)
14054 {
14055     if (aa == 'A' || aa == 'a')      /* Ala */
14056         {
14057         return 1;
14058         }
14059     else if (aa == 'R' || aa == 'r') /* Arg */
14060         {
14061         return 2;
14062         }
14063     else if (aa == 'N' || aa == 'n') /* Asn */
14064         {
14065         return 4;
14066         }
14067     else if (aa == 'D' || aa == 'd') /* Asp */
14068         {
14069         return 8;
14070         }
14071     else if (aa == 'C' || aa == 'c') /* Cys */
14072         {
14073         return 16;
14074         }
14075     else if (aa == 'Q' || aa == 'q') /* Gln */
14076         {
14077         return 32;
14078         }
14079     else if (aa == 'E' || aa == 'e') /* Glu */
14080         {
14081         return 64;
14082         }
14083     else if (aa == 'G' || aa == 'g') /* Gly */
14084         {
14085         return 128;
14086         }
14087     else if (aa == 'H' || aa == 'h') /* His */
14088         {
14089         return 256;
14090         }
14091     else if (aa == 'I' || aa == 'i') /* Ile */
14092         {
14093         return 512;
14094         }
14095     else if (aa == 'L' || aa == 'l') /* Leu */
14096         {
14097         return 1024;
14098         }
14099     else if (aa == 'K' || aa == 'k') /* Lys */
14100         {
14101         return 2048;
14102         }
14103     else if (aa == 'M' || aa == 'm') /* Met */
14104         {
14105         return 4096;
14106         }
14107     else if (aa == 'F' || aa == 'f') /* Phe */
14108         {
14109         return 8192;
14110         }
14111     else if (aa == 'P' || aa == 'p') /* Pro */
14112         {
14113         return 16384;
14114         }
14115     else if (aa == 'S' || aa == 's') /* Ser */
14116         {
14117         return 32768;
14118         }
14119     else if (aa == 'T' || aa == 't') /* Thr */
14120         {
14121         return 65536;
14122         }
14123     else if (aa == 'W' || aa == 'w') /* Trp */
14124         {
14125         return 131072;
14126         }
14127     else if (aa == 'Y' || aa == 'y') /* Tyr */
14128         {
14129         return 262144;
14130         }
14131     else if (aa == 'V' || aa == 'v') /* Val */
14132         {
14133         return 524288;
14134         }
14135     else if (aa == 'X' || aa == 'x') /* Nonidentified */
14136         {
14137         return MISSING;
14138         }
14139     else if (aa == gapId)
14140         {
14141         return GAP;
14142         }
14143     else if (aa == missingId)
14144         {
14145         return MISSING;
14146         }
14147     else
14148         return -1;
14149 }
14150 
14151 
RemoveLastFromString(char * s1)14152 int RemoveLastFromString (char *s1)
14153 {
14154     int     i, j, numPrev, numRemoved;
14155 
14156     /* We remove the last name from the string simply by deleting the last "|". */
14157 
14158     i = numPrev = 0;
14159     while (s1[i] != '\0')
14160         {
14161         if (s1[i] == '|')
14162             numPrev++;
14163         i++;
14164         }
14165 
14166     i = j = numRemoved = 0;
14167     while (s1[i] != '\0')
14168         {
14169         if (s1[i] == '|')
14170             j++;
14171         if (numPrev == j)
14172             {
14173             s1[i] = ' ';
14174             numRemoved++;
14175             break;
14176             }
14177         i++;
14178         }
14179 
14180     if (numRemoved != 1)
14181         {
14182         MrBayesPrint ("%s   Could not find name to remove\n", spacer);
14183         return (ERROR);
14184         }
14185 
14186     return (NO_ERROR);
14187 }
14188 
14189 
MBResID(char nuc)14190 int MBResID (char nuc)
14191 {
14192     char        n;
14193 
14194     n = nuc;
14195 
14196     if (n == '0' || n == 'a' || n == 'A')
14197         {
14198         return 1;
14199         }
14200     else if (n == '1' || n == 'b' || n == 'B')
14201         {
14202         return 2;
14203         }
14204     else if (n == gapId)
14205         {
14206         return GAP;
14207         }
14208     else if (n == missingId)
14209         {
14210         return MISSING;
14211         }
14212     else
14213         return -1;
14214 }
14215 
14216 
14217 /* Reset character flags */
ResetCharacterFlags(void)14218 void ResetCharacterFlags (void)
14219 {
14220     /* reset all characters flags */
14221     numChar              = 0;                        /* number of defined characters                  */
14222     defChars             = NO;                       /* flag for whether number of characters is known*/
14223     defMatrix            = NO;                       /* flag for whether matrix is successfull read   */
14224     matrixHasPoly        = NO;                       /* flag for whether matrix has polymorphisms     */
14225     isInAmbig            = NO;                       /* flag for whether the parser is within ()      */
14226     isInPoly             = NO;                       /* flag for whether the parser is within {}      */
14227     defPartition         = NO;                       /* flag for whether character partition is read  */
14228     defPairs             = NO;                       /* flag indicating whether pairs have been defnd */
14229     numDefinedPartitions = 0;                        /* number of defined partitions                  */
14230     partitionNum         = 0;                        /* partition number currently enforced           */
14231     numCurrentDivisions  = 0;                        /* number of partitions of data                  */
14232     numCharSets          = 0;                        /* holds number of character sets                */
14233     numDivisions         = 1;                        /* holds number of partitions                    */
14234     isMixed              = NO;                       /* are data mixed ?                              */
14235     dataType             = NONE;                     /* holds datatype                                */
14236     matchId              = '\0';                     /* no default for match character                */
14237     gapId                = '\0';                     /* no default for gap character                  */
14238     missingId            = '\0';                     /* no default for missing characters             */
14239 }
14240 
14241 
14242 /* Reset taxa flags */
ResetTaxaFlags(void)14243 void ResetTaxaFlags (void)
14244 {
14245     numTaxa                 = 0;                         /* number of taxa                                */
14246     numNamedTaxa            = 0;                         /* number of named taxa                          */
14247     defTaxa                 = NO;                        /* flag for whether number of taxa is known      */
14248     isTaxsetDef             = NO;                        /* is a taxlabels set defined                    */
14249     numDefinedConstraints   = 0;                         /* holds number of defined constraints           */
14250     definedConstraint       = NULL;
14251     definedConstraintTwo    = NULL;
14252     definedConstraintPruned       = NULL;
14253     definedConstraintTwoPruned    = NULL;
14254     constraintNames         = NULL;
14255     nodeCalibration         = NULL;
14256     tempActiveConstraints   = NULL;                      /* holds temp info on active constraints         */
14257     outGroupNum             = 0;                         /* default outgroup                              */
14258     numTaxaSets             = 0;                         /* holds number of taxa sets                     */
14259 }
14260 
14261 
14262 /* SetPartition: Set model partition */
SetPartition(int part)14263 int SetPartition (int part)
14264 {
14265     int     i, j;
14266 
14267     /* Free space for modelParams and modelSettings */
14268     if (memAllocs[ALLOC_MODEL] == YES)
14269         {
14270         for (i=0; i<numCurrentDivisions; i++)
14271           free (modelParams[i].activeConstraints);
14272         free (modelParams);
14273         free (modelSettings);
14274         modelParams = NULL;
14275         modelSettings = NULL;
14276         memAllocs[ALLOC_MODEL] = NO;
14277         }
14278 
14279     /* Set model partition */
14280     partitionNum = part;
14281     numCurrentDivisions = 0;
14282 
14283     /* Set numCurrentDivisions to maximum division a character belongs to in partition part */
14284     for (i=0; i<numChar; i++)
14285         {
14286         j = partitionId[i][part];
14287         if (j > numCurrentDivisions)
14288             numCurrentDivisions = j;
14289         }
14290 
14291     /* Allocate space for partition models */
14292     modelParams = (Model *) SafeCalloc (numCurrentDivisions, sizeof (Model));
14293     modelSettings = (ModelInfo *) SafeCalloc (numCurrentDivisions, sizeof (ModelInfo));
14294     if (!modelParams || !modelSettings)
14295         {
14296         MrBayesPrint ("%s   Could not allocate modelParams or modelSettings\n", spacer);
14297         if (modelParams)
14298             free (modelParams);
14299         if (modelSettings)
14300             free (modelSettings);
14301         return (ERROR);
14302         }
14303     memAllocs[ALLOC_MODEL] = YES;
14304 
14305     numVars = (int *) SafeRealloc ((void *) numVars, 3 * (size_t)numCurrentDivisions * sizeof(int));
14306     tempLinkUnlinkVec = numVars + numCurrentDivisions;
14307     activeParts       = numVars + 2*numCurrentDivisions;
14308 
14309     tempNum = (MrBFlt *) SafeRealloc ((void *) tempNum, 6 * sizeof(MrBFlt));
14310 
14311     activeParams[0] = (int *) SafeRealloc ((void *) (activeParams[0]), (size_t)NUM_LINKED * (size_t)numCurrentDivisions * sizeof(int));
14312     for (i=1; i<NUM_LINKED; i++)
14313         activeParams[i] = activeParams[0] + i*numCurrentDivisions;
14314 
14315     linkTable[0] = (int *) SafeRealloc ((void *) (linkTable[0]), 3 * (size_t)NUM_LINKED * (size_t)numCurrentDivisions * sizeof(int));
14316     tempLinkUnlink[0] = linkTable[0] + NUM_LINKED*numCurrentDivisions;
14317     for (i=1; i<NUM_LINKED; i++)
14318         {
14319         linkTable[i]      = linkTable[0] + i*numCurrentDivisions;
14320         tempLinkUnlink[i] = tempLinkUnlink[0] + i*numCurrentDivisions;
14321         }
14322 
14323     return (NO_ERROR);
14324 }
14325 
14326 
14327 /* SetSpeciespartition: Set speciespartition */
SetSpeciespartition(int part)14328 int SetSpeciespartition (int part)
14329 {
14330     int     i, j;
14331 
14332     /* Set model partition */
14333     speciespartitionNum = part;
14334     numSpecies = 0;
14335 
14336     /* Set numSpecies to maximum species a taxon belongs to in partition part */
14337     for (i=0; i<numTaxa; i++)
14338         {
14339         j = speciespartitionId[i][part];
14340         if (j > numSpecies)
14341             numSpecies = j;
14342         }
14343 
14344     return (NO_ERROR);
14345 }
14346 
14347 
SetTaxaFromTranslateTable(void)14348 int SetTaxaFromTranslateTable (void)
14349 {
14350     int     i;
14351 
14352     if (numTaxa != 0)
14353         return ERROR;
14354 
14355     for (i=0; i<numTranslates; i++)
14356         {
14357         if (strlen(transFrom[i])>99)
14358             {
14359             MrBayesPrint ("%s   Taxon name %s is too long. Maximun 99 characters is allowed.\n", spacer, transFrom[i]);
14360             return (ERROR);
14361             }
14362         AddString(&taxaNames, numTaxa, transFrom[i]);
14363         numTaxa++;
14364         }
14365 
14366     return NO_ERROR;
14367 }
14368 
14369 
SetUpParms(void)14370 void SetUpParms (void)
14371 {
14372     ParmInfoPtr p = paramTable;
14373 
14374     PARAM   (0, "NEXUS",          DoNexusParm,       "NEXUS|\0");
14375     PARAM   (1, "Data",           DoBeginParm,       "\0");
14376     PARAM   (2, "Mrbayes",        DoBeginParm,       "\0");
14377     PARAM   (3, "Trees",          DoBeginParm,       "\0");
14378     PARAM   (4, "Ntax",           DoDimensionsParm,  "\0");
14379     PARAM   (5, "Nchar",          DoDimensionsParm,  "\0");
14380     PARAM   (6, "Interleave",     DoFormatParm,      "Yes|No|\0");
14381     PARAM   (7, "Datatype",       DoFormatParm,      "Dna|Rna|Protein|Restriction|Standard|Continuous|Mixed|\0");
14382     PARAM   (8, "Gap",            DoFormatParm,      "\0");
14383     PARAM   (9, "Missing",        DoFormatParm,      "\0");
14384     PARAM  (10, "Matchchar",      DoFormatParm,      "\0");
14385     PARAM  (11, "MatrixInfo",     DoMatrixParm,      "\0");
14386     PARAM  (12, "Filename",       DoExecuteParm,     "\0");
14387     PARAM  (13, "Autoclose",      DoSetParm,         "Yes|No|\0");
14388     PARAM  (14, "Partition",      DoSetParm,         "\0");
14389     PARAM  (15, "Xxxxxxxxxx",     DoCharsetParm,     "\0");
14390     PARAM  (16, "Xxxxxxxxxx",     DoPartitionParm,   "\0");
14391     PARAM  (17, "Seed",           DoMcmcParm,        "\0");
14392     PARAM  (18, "Ngen",           DoMcmcParm,        "\0");
14393     PARAM  (19, "Samplefreq",     DoMcmcParm,        "\0");
14394     PARAM  (20, "Printfreq",      DoMcmcParm,        "\0");
14395     PARAM  (21, "Nchains",        DoMcmcParm,        "\0");
14396     PARAM  (22, "Temp",           DoMcmcParm,        "\0");
14397     PARAM  (23, "Filename",       DoMcmcParm,        "\0");
14398     PARAM  (24, "Burnin",         DoMcmcParm,        "\0");
14399     PARAM  (25, "Starttree",      DoMcmcParm,        "Random|Current|User|Parsimony|NJ|\0");
14400     PARAM  (26, "Nperts",         DoMcmcParm,        "\0");
14401     PARAM  (27, "Savebrlens",     DoMcmcParm,        "Yes|No|\0");
14402     PARAM  (28, "Nucmodel",       DoLsetParm,        "4by4|Doublet|Codon|Protein|\0");
14403     PARAM  (29, "Nst",            DoLsetParm,        "1|2|6|Mixed|\0");
14404     PARAM  (30, "Aamodel",        DoLsetParm,        "Poisson|Equalin|Jones|Dayhoff|Mtrev|Mtmam|Wag|Rtrev|Cprev|Vt|Blosum|Blossum|LG|\0");
14405     PARAM  (31, "Parsmodel",      DoLsetParm,        "Yes|No|\0");
14406     PARAM  (32, "Omegavar",       DoLsetParm,        "Equal|Ny98|M3|M10|\0");
14407     PARAM  (33, "Code",           DoLsetParm,        "Universal|Vertmt|Invermt|Mycoplasma|Yeast|Ciliate|Echinoderm|Euplotid|Metmt|\0");
14408     PARAM  (34, "Coding",         DoLsetParm,        "All|Variable|Informative|Nosingletons|Noabsencesites|Nopresencesites|Nosingletonpresence|Nosingletonabsence|\0");
14409     PARAM  (35, "Seqerror",       DoPrsetParm,       "\0");
14410     PARAM  (36, "Tratiopr",       DoPrsetParm,       "Beta|Fixed|\0");
14411     PARAM  (37, "Revmatpr",       DoPrsetParm,       "Dirichlet|Fixed|\0");
14412     PARAM  (38, "Omegapr",        DoPrsetParm,       "Dirichlet|Fixed|\0");
14413     PARAM  (39, "Statefreqpr",    DoPrsetParm,       "Dirichlet|Fixed|\0");
14414     PARAM  (40, "Ngammacat",      DoLsetParm,        "\0");
14415     PARAM  (41, "Shapepr",        DoPrsetParm,       "Uniform|Exponential|Fixed|\0");
14416     PARAM  (42, "Ratecorrpr",     DoPrsetParm,       "Uniform|Fixed|\0");
14417     PARAM  (43, "Pinvarpr",       DoPrsetParm,       "Uniform|Fixed|\0");
14418     PARAM  (44, "Covswitchpr",    DoPrsetParm,       "Uniform|Exponential|Fixed|\0");
14419     PARAM  (45, "Xxxxxxxxxx",     DoExcludeParm,     "\0");
14420     PARAM  (46, "Xxxxxxxxxx",     DoIncludeParm,     "\0");
14421     PARAM  (47, "Xxxxxxxxxx",     DoDeleteParm,      "\0");
14422     PARAM  (48, "Xxxxxxxxxx",     DoRestoreParm,     "\0");
14423     PARAM  (49, "Xxxxxxxxxx",     DoTaxasetParm,     "\0");
14424     PARAM  (50, "Xxxxxxxxxx",     DoHelpParm,        "\0");
14425     PARAM  (51, "Applyto",        DoLsetParm,        "\0");
14426     PARAM  (52, "Rates",          DoLsetParm,        "Equal|Gamma|LNorm|Propinv|Invgamma|Adgamma|Kmixture|\0");
14427     PARAM  (53, "Covarion",       DoLsetParm,        "Yes|No|\0");
14428     PARAM  (54, "Applyto",        DoPrsetParm,       "\0");
14429     PARAM  (55, "Tratio",         DoLinkParm,        "\0");
14430     PARAM  (56, "Revmat",         DoLinkParm,        "\0");
14431     PARAM  (57, "Omega",          DoLinkParm,        "\0");
14432     PARAM  (58, "Statefreq",      DoLinkParm,        "\0");
14433     PARAM  (59, "Shape",          DoLinkParm,        "\0");
14434     PARAM  (60, "Pinvar",         DoLinkParm,        "\0");
14435     PARAM  (61, "Correlation",    DoLinkParm,        "\0");
14436     PARAM  (62, "Ratemultiplier", DoLinkParm,        "\0");
14437     PARAM  (63, "Switchrates",    DoLinkParm,        "\0");
14438     PARAM  (64, "Symdirihyperpr", DoPrsetParm,       "Uniform|Exponential|Fixed|\0");
14439     PARAM  (65, "Xxxxxxxxxx",     DoCtypeParm,       "\0");
14440     PARAM  (66, "Xxxxxxxxxx",     DoConstraintParm,  "\0");
14441     PARAM  (67, "Topologypr",     DoPrsetParm,       "Uniform|Constraints|Fixed|Speciestree|\0");
14442     PARAM  (68, "Brlenspr",       DoPrsetParm,       "Unconstrained|Clock|Relaxedclock|Fixed|\0");
14443     PARAM  (69, "Speciationpr",   DoPrsetParm,       "Uniform|Exponential|Fixed|\0");
14444     PARAM  (70, "Extinctionpr",   DoPrsetParm,       "Beta|Fixed|\0");
14445     PARAM  (71, "Popsizepr",      DoPrsetParm,       "Lognormal|Uniform|Gamma|Normal|Fixed|\0");
14446     PARAM  (72, "Topology",       DoLinkParm,        "\0");
14447     PARAM  (73, "Brlens",         DoLinkParm,        "\0");
14448     PARAM  (74, "Speciationrate", DoLinkParm,        "\0");
14449     PARAM  (75, "Extinctionrate", DoLinkParm,        "\0");
14450     PARAM  (76, "Popsize",        DoLinkParm,        "\0");
14451     PARAM  (77, "Ratepr",         DoPrsetParm,       "Variable|Dirichlet|Fixed|\0");
14452     PARAM  (78, "Xxxxxxxxxx",     DoOutgroupParm,    "\0");
14453     PARAM  (79, "Xxxxxxxxxx",     DoTreeParm,        "\0");
14454     PARAM  (80, "Filename",       DoSumtParm,        "\0");
14455     PARAM  (81, "Burnin",         DoSumtParm,        "\0");
14456     PARAM  (82, "Contype",        DoSumtParm,        "Halfcompat|Allcompat|\0");
14457     PARAM  (83, "Xxxxxxxxxx",     DoTranslateParm,   "\0");
14458     PARAM  (84, "Swapfreq",       DoMcmcParm,        "\0");
14459     PARAM  (85, "Start",          DoLogParm,         "\0");
14460     PARAM  (86, "Stop",           DoLogParm,         "\0");
14461     PARAM  (87, "Filename",       DoLogParm,         "\0");
14462     PARAM  (88, "Append",         DoLogParm,         "\0");
14463     PARAM  (89, "Replace",        DoLogParm,         "\0");
14464     PARAM  (90, "Nbetacat",       DoLsetParm,        "\0");
14465     PARAM  (91, "Augment",        DoLsetParm,        "Yes|No|\0");
14466     PARAM  (92, "Xxxxxxxxxx",     DoPairsParm,       "\0");
14467     PARAM  (93, "Xxxxxxxxxx",     DoBreaksParm,      "\0");
14468     PARAM  (94, "Nowarnings",     DoSetParm,         "Yes|No|\0");
14469     PARAM  (95, "Showtreeprobs",  DoSumtParm,        "Yes|No|\0");
14470     PARAM  (96, "Filename",       DoSumpParm,        "\0");
14471     PARAM  (97, "Burnin",         DoSumpParm,        "\0");
14472     PARAM  (98, "Reweight",       DoMcmcParm,        "\0");
14473     PARAM  (99, "Noop",           DoMcmcParm,        "\0");
14474     PARAM (100, "Ny98omega1pr",   DoPrsetParm,       "Beta|Fixed|\0");
14475     PARAM (101, "Ny98omega3pr",   DoPrsetParm,       "Uniform|Exponential|Fixed|\0");
14476     PARAM (102, "Codoncatfreqs",  DoPrsetParm,       "Dirichlet|Fixed|\0");
14477     PARAM (103, "Sampleprob",     DoPrsetParm,       "\0");
14478     PARAM (104, "Aamodelpr",      DoPrsetParm,       "Fixed|Mixed|\0");
14479     PARAM (105, "Aamodel",        DoLinkParm,        "\0");
14480     PARAM (106, "Filename",       DoPlotParm,        "\0");
14481     PARAM (107, "Parameter",      DoPlotParm,        "\0");
14482     PARAM (108, "Match",          DoPlotParm,        "Perfect|Consistentwith|All|\0");
14483     PARAM (109, "Burnin",         DoPlotParm,        "\0");
14484     PARAM (110, "Brownscalepr",   DoPrsetParm,       "Uniform|Gamma|Gammamean|Fixed|\0");
14485     PARAM (111, "Browncorrpr",    DoPrsetParm,       "Uniform|Fixed|\0");
14486     PARAM (112, "Pbf",            DoMcmcParm,        "Yes|No|\0");
14487     PARAM (113, "Pbfinitburnin",  DoMcmcParm,        "\0");
14488     PARAM (114, "Pbfsamplefreq",  DoMcmcParm,        "\0");
14489     PARAM (115, "Pbfsampletime",  DoMcmcParm,        "\0");
14490     PARAM (116, "Pbfsampleburnin",DoMcmcParm,        "\0");
14491     PARAM (117, "Growthpr",       DoPrsetParm,       "Uniform|Exponential|Fixed|Normal|\0");
14492     PARAM (118, "Growthrate",     DoLinkParm,        "\0");
14493     PARAM (119, "Xxxxxxxxxx",     DoCalibrateParm,   "Unconstrained|Fixed|Uniform|Offsetexponential|Truncatednormal|Lognormal|Offsetlognormal|Gamma|Offsetgamma|\0");
14494     PARAM (120, "Calwaitpr",      DoPrsetParm,       "Exponential|Fixed|\0");     /* not used but leave it in to not destroy mapping to commands */
14495     PARAM (121, "M3omegapr",      DoPrsetParm,       "Exponential|Fixed|\0");
14496     PARAM (122, "Applyto",        DoReportParm,      "\0");
14497     PARAM (123, "Tratio",         DoReportParm,      "Dirichlet|Ratio|\0");
14498     PARAM (124, "Revmat",         DoReportParm,      "Dirichlet|Ratio|\0");
14499     PARAM (125, "Ratemult",       DoReportParm,      "Dirichlet|Scaled|Ratio|\0");
14500     PARAM (126, "Filename",       DoManualParm,      "\0");
14501     PARAM (127, "Filename1",      DoCompareTreeParm, "\0");
14502     PARAM (128, "Filename2",      DoCompareTreeParm, "\0");
14503     PARAM (129, "Outputname",     DoCompareTreeParm, "\0");
14504     PARAM (130, "Burnin",         DoCompareTreeParm, "\0");
14505     PARAM (131, "Ploidy",         DoLsetParm,        "Haploid|Diploid|Zlinked|\0");
14506     PARAM (132, "Swapadjacent",   DoMcmcParm,        "Yes|No|\0");
14507     PARAM (133, "Treeagepr",      DoPrsetParm,       "Fixed|Uniform|Offsetexponential|Truncatednormal|Lognormal|Offsetlognormal|Gamma|Offsetgamma|\0");
14508     PARAM (134, "Ancstates",      DoReportParm,      "Yes|No|\0");
14509     PARAM (135, "Siterates",      DoReportParm,      "Yes|No|\0");
14510     PARAM (136, "Possel",         DoReportParm,      "Yes|No|\0");
14511     PARAM (137, "Plot",           DoSumpParm,        "Yes|No|\0");
14512     PARAM (138, "Table",          DoSumpParm,        "Yes|No|\0");
14513     PARAM (139, "Minprob",        DoSumpParm,        "\0");
14514     PARAM (140, "Printtofile",    DoSumpParm,        "Yes|No|\0");
14515     PARAM (141, "Outputname",     DoSumpParm,        "\0");
14516     PARAM (142, "Redirect",       DoMcmcParm,        "Yes|No|\0");
14517     PARAM (143, "Swapseed",       DoMcmcParm,        "\0");
14518     PARAM (144, "Runidseed",      DoMcmcParm,        "\0");
14519     PARAM (145, "Quitonerror",    DoSetParm,         "Yes|No|\0");
14520     PARAM (146, "Savebrparams",   DoSumtParm,        "Yes|No|\0");
14521     PARAM (147, "Minbrparamfreq", DoSumtParm,        "\0");
14522     PARAM (148, "Minpartfreq",    DoMcmcParm,        "\0");
14523     PARAM (149, "Allchains",      DoMcmcParm,        "Yes|No|\0");
14524     PARAM (150, "Mcmcdiagn",      DoMcmcParm,        "Yes|No|\0");
14525     PARAM (151, "Diagnfreq",      DoMcmcParm,        "\0");
14526     PARAM (152, "Nruns",          DoMcmcParm,        "\0");
14527     PARAM (153, "Stoprule",       DoMcmcParm,        "Yes|No|\0");
14528     PARAM (154, "Stopval",        DoMcmcParm,        "\0");
14529     PARAM (155, "Relburnin",      DoMcmcParm,        "Yes|No|\0");
14530     PARAM (156, "Burninfrac",     DoMcmcParm,        "\0");
14531     PARAM (157, "Allcomps",       DoMcmcParm,        "Yes|No|\0");
14532     PARAM (158, "Printall",       DoMcmcParm,        "Yes|No|\0");
14533     PARAM (159, "Printmax",       DoMcmcParm,        "\0");
14534     PARAM (160, "Data",           DoMcmcParm,        "Yes|No|\0");
14535     PARAM (161, "Nruns",          DoSumpParm,        "\0");
14536     PARAM (162, "Allruns",        DoSumpParm,        "Yes|No|\0");
14537     PARAM (163, "Nruns",          DoSumtParm,        "\0");
14538     PARAM (164, "Ntrees",         DoSumtParm,        "\0");
14539     PARAM (165, "Calctreeprobs",  DoSumtParm,        "Yes|No|\0");
14540     PARAM (166, "Ordertaxa",      DoMcmcParm,        "Yes|No|\0");
14541     PARAM (167, "Ordertaxa",      DoSumtParm,        "Yes|No|\0");
14542     PARAM (168, "Aarevmatpr",     DoPrsetParm,       "Dirichlet|Fixed|\0");
14543     PARAM (169, "Nswaps",         DoMcmcParm,        "\0");
14544     PARAM (170, "Autoreplace",    DoSetParm,         "Yes|No|\0");
14545     PARAM (171, "Npthreads",      DoSetParm,         "\0");
14546     PARAM (172, "Cppratepr",      DoPrsetParm,       "Fixed|Exponential|\0");
14547     PARAM (173, "Cppmultdevpr",   DoPrsetParm,       "Fixed|\0");
14548     PARAM (174, "TK02varpr",      DoPrsetParm,       "Fixed|Exponential|Uniform|\0");
14549     PARAM (175, "Pfile",          DoSumtParm,        "\0");
14550     PARAM (176, "Pfile",          DoSumtParm,        "\0");
14551     PARAM (177, "Autocomplete",   DoSumtParm,        "Yes|No|\0");
14552     PARAM (178, "Autocomplete",   DoSumpParm,        "Yes|No|\0");
14553     PARAM (179, "Userlevel",      DoSetParm,         "Standard|Developer|\0");
14554     PARAM (180, "Allavailable",   DoShowmovesParm,   "Yes|No|\0");
14555     PARAM (181, "Seed",           DoSetParm,         "\0");
14556     PARAM (182, "Swapseed",       DoSetParm,         "\0");
14557     PARAM (183, "Clockratepr",    DoPrsetParm,       "Fixed|Normal|Lognormal|Exponential|Gamma|\0");
14558     PARAM (184, "Nodeagepr",      DoPrsetParm,       "Unconstrained|Calibrated|\0");
14559     PARAM (185, "Clockvarpr",     DoPrsetParm,       "Strict|Cpp|TK02|Igr|Bm|Ibr|Mixed|\0");
14560     PARAM (186, "Xxxxxxxxxx",     DoPropsetParm,     "\0");
14561     PARAM (187, "Xxxxxxxxxx",     DoStartvalsParm,   "\0");
14562     PARAM (188, "Usegibbs",       DoLsetParm,        "Yes|No|\0");
14563     PARAM (189, "Gibbsfreq",      DoLsetParm,        "\0");
14564     PARAM (190, "Checkpoint",     DoMcmcParm,        "Yes|No|\0");
14565     PARAM (191, "Checkfreq",      DoMcmcParm,        "\0");
14566     PARAM (192, "Tree",           DoReportParm,      "Topology|Brlens|\0");
14567     PARAM (193, "Cpprate",        DoLinkParm,        "\0");
14568     PARAM (194, "Cppmultdev",     DoLinkParm,        "\0");
14569     PARAM (195, "Cppevents",      DoLinkParm,        "\0");
14570     PARAM (196, "TK02var",        DoLinkParm,        "\0");
14571     PARAM (197, "TK02branchrates",DoLinkParm,        "\0");
14572     PARAM (198, "Savetrees",      DoMcmcParm,        "Yes|No|\0");
14573     PARAM (199, "Diagnstat",      DoMcmcParm,        "Avgstddev|Maxstddev|\0");
14574     PARAM (200, "Startparams",    DoMcmcParm,        "Reset|Current|\0");
14575     PARAM (201, "Characters",     DoBeginParm,       "\0");
14576     PARAM (202, "Startingtrees",  DoMcmcParm,        "\0");
14577     PARAM (203, "Xxxxxxxxxx",     DoUserTreeParm,    "\0");
14578     PARAM (204, "Outputname",     DoSumtParm,        "\0");
14579     PARAM (205, "Table",          DoSumtParm,        "Yes|No|\0");
14580     PARAM (206, "Summary",        DoSumtParm,        "Yes|No|\0");
14581     PARAM (207, "Consensus",      DoSumtParm,        "Yes|No|\0");
14582     PARAM (208, "Minpartfreq",    DoSumtParm,        "\0");
14583     PARAM (209, "Relburnin",      DoSumtParm,        "Yes|No|\0");
14584     PARAM (210, "Burninfrac",     DoSumtParm,        "\0");
14585     PARAM (211, "Relburnin",      DoSumpParm,        "Yes|No|\0");
14586     PARAM (212, "Burninfrac",     DoSumpParm,        "\0");
14587     PARAM (213, "Append",         DoMcmcParm,        "Yes|No|\0");
14588     PARAM (214, "Autotune",       DoMcmcParm,        "Yes|No|\0");
14589     PARAM (215, "Tunefreq",       DoMcmcParm,        "\0");
14590     PARAM (216, "Scientific",     DoSetParm,         "Yes|No|\0");
14591     PARAM (217, "Siteomega",      DoReportParm,      "Yes|No|\0");
14592     PARAM (218, "Igrvarpr",       DoPrsetParm,       "Fixed|Exponential|Uniform|\0");
14593     PARAM (219, "Symbols",        DoFormatParm,      "\0");
14594     PARAM (220, "Equate",         DoFormatParm,      "\0");
14595     PARAM (221, "Relburnin",      DoCompareTreeParm, "Yes|No|\0");
14596     PARAM (222, "Burninfrac",     DoCompareTreeParm, "\0");
14597     PARAM (223, "Minpartfreq",    DoCompareTreeParm, "\0");
14598     PARAM (224, "Relburnin",      DoPlotParm,        "Yes|No|\0");
14599     PARAM (225, "Burninfrac",     DoPlotParm,        "\0");
14600     PARAM (226, "Taxa",           DoBeginParm,       "\0");
14601     PARAM (227, "Xxxxxxxxxx",     DoBeginParm,       "\0");
14602     PARAM (228, "Xxxxxxxxxx",     DoTaxlabelsParm,   "\0");
14603     PARAM (229, "Dir",            DoSetParm,         "\0");
14604     PARAM (230, "Conformat",      DoSumtParm,        "Figtree|Simple|\0");
14605     PARAM (231, "Hpd",            DoSumpParm,        "Yes|No|\0");
14606     PARAM (232, "Hpd",            DoSumtParm,        "Yes|No|\0");
14607     PARAM (233, "Usebeagle",      DoSetParm,         "Yes|No|\0");
14608     PARAM (234, "Beagledevice",   DoSetParm,         "Cpu|Gpu|\0");
14609     PARAM (235, "Beagleprecision",DoSetParm,         "Single|Double|\0");
14610     PARAM (236, "Beaglesse",      DoSetParm,         "Yes|No|\0");
14611     PARAM (237, "Beagleopenmp",   DoSetParm,         "Yes|No|\0");
14612     PARAM (238, "Beaglethreads",  DoSetParm,         "Yes|No|\0");
14613     PARAM (239, "Beaglescaling",  DoSetParm,         "Always|Dynamic|\0");
14614     PARAM (240, "Beaglefreq",     DoSetParm,         "\0");
14615     PARAM (241, "Popvarpr",       DoPrsetParm,       "Equal|Variable|\0");
14616     PARAM (242, "Igrvar",         DoLinkParm,        "\0");
14617     PARAM (243, "Igrbranchrates", DoLinkParm,        "\0");
14618     PARAM (244, "Xxxxxxxxxx",     DoSpeciespartitionParm,   "\0");
14619     PARAM (245, "Speciespartition",  DoSetParm,      "\0");
14620     PARAM (246, "Revratepr",      DoPrsetParm,       "Symdir|\0");
14621     PARAM (247, "Samplestrat",    DoPrsetParm,       "Random|Diversity|Cluster|FossilTip|\0");
14622     PARAM (248, "Burninss",       DoSsParm,          "\0");
14623     PARAM (249, "Nsteps",         DoSsParm,          "\0");
14624     PARAM (250, "Alpha",          DoSsParm,          "\0");
14625     PARAM (251, "Bmvarpr",        DoPrsetParm,       "Fixed|Exponential|Uniform|\0");
14626     PARAM (252, "Bmvar",          DoLinkParm,        "\0");
14627     PARAM (253, "Bmbranchrates",  DoLinkParm,        "\0");
14628     PARAM (254, "Ibrvarpr",       DoPrsetParm,       "Fixed|Exponential|Uniform|\0");
14629     PARAM (255, "Ibrvar",         DoLinkParm,        "\0");
14630     PARAM (256, "Ibrbranchlens",  DoLinkParm,        "\0");
14631     PARAM (257, "FromPrior",      DoSsParm,          "Yes|No|\0");
14632     PARAM (258, "Filename",       DoSumSsParm,       "\0");
14633     PARAM (259, "Burnin",         DoSumSsParm,       "\0");
14634     PARAM (260, "Nruns",          DoSumSsParm,       "\0");
14635     PARAM (261, "Allruns",        DoSumSsParm,       "Yes|No|\0");
14636     PARAM (262, "Askmore",        DoSumSsParm,       "Yes|No|\0");
14637     PARAM (263, "Relburnin",      DoSumSsParm,       "Yes|No|\0");
14638     PARAM (264, "Burninfrac",     DoSumSsParm,       "\0");
14639     PARAM (265, "Discardfrac",    DoSumSsParm,       "\0");
14640     PARAM (266, "Smoothing",      DoSumSsParm,       "\0");
14641     PARAM (267, "Steptoplot",     DoSumSsParm,       "\0");
14642     PARAM (268, "Precision",      DoSetParm,         "\0");
14643     PARAM (269, "Fossilizationpr",   DoPrsetParm,    "Beta|Fixed|\0");
14644     PARAM (270, "Fossilizationrate", DoLinkParm,     "\0");
14645     PARAM (271, "Generatepr",     DoPrsetParm,       "Variable|Fixed|\0");
14646     PARAM (272, "Mixedvarpr",     DoPrsetParm,       "Fixed|Exponential|Uniform|\0");
14647     PARAM (273, "Mixedvar",       DoLinkParm,        "\0");
14648     PARAM (274, "Mixedbrchrates", DoLinkParm,        "\0");
14649     PARAM (275, "Beagleresource", DoSetParm,         "\0");
14650     PARAM (276, "Nlnormcat",      DoLsetParm,        "\0");
14651     PARAM (277, "Nmixtcat",       DoLsetParm,        "\0");
14652     PARAM (278, "Beaglethreadcount",  DoSetParm,     "\0");
14653     PARAM (279, "Beaglefloattips",DoSetParm,  "Yes|No|\0");
14654 
14655 
14656     /* NOTE: If a change is made to the parameter table, make certain you change
14657             NUMPARAMS (now 280; one more than last index) at the top of this file. */
14658     /* CmdType commands[] */
14659 }
14660 
14661 
ShowNodes(TreeNode * p,int indent,int isThisTreeRooted)14662 void ShowNodes (TreeNode *p, int indent, int isThisTreeRooted)
14663 {
14664     if (p != NULL)
14665         {
14666         printf ("   ");
14667         if (p->left == NULL && p->right == NULL && p->anc != NULL)
14668             {
14669             printf ("%*cN %d (l=%d r=%d a=%d) %1.15lf (%s) isDated=%d ",
14670             indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc), p->length, p->label, p->isDated);
14671             }
14672         else if (p->left != NULL && p->right == NULL && p->anc == NULL)
14673             {
14674             if (isThisTreeRooted == NO)
14675                 {
14676                 if (p->label[0] == '\0' || p->label[0] == '\n' || p->label[0] == ' ')
14677                     printf ("%*cN %d (l=%d r=%d a=%d) (---) ",
14678                     indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc));
14679                 else
14680                     printf ("%*cN %d (l=%d r=%d a=%d) (%s) ",
14681                     indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc), p->label);
14682                 }
14683             else
14684                 {
14685                 printf ("%*cN %d (l=%d r=%d a=%d) X.XXXXXX ",
14686                 indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc));
14687                 }
14688             }
14689         else
14690             {
14691             if (p->anc != NULL)
14692                 {
14693                 if (p->anc->anc == NULL && isThisTreeRooted == YES)
14694                     printf ("%*cN %d (l=%d r=%d a=%d) X.XXXXXX ",
14695                     indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc));
14696                 else
14697                     printf ("%*cN %d (l=%d r=%d a=%d) %1.15lf ",
14698                     indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc), p->length);
14699                 }
14700             }
14701         if (isThisTreeRooted == YES)
14702             printf ("depth=%1.15lf\n", p->nodeDepth);
14703         else
14704             printf ("\n");
14705         ShowNodes (p->left,  indent + 2, isThisTreeRooted);
14706         ShowNodes (p->right, indent + 2, isThisTreeRooted);
14707         }
14708 }
14709 
14710 
StandID(char nuc)14711 int StandID (char nuc)
14712 {
14713     char        n;
14714 
14715     /* Note that if you change how many states are recognized, you need
14716        to look at IsMissing */
14717     n = nuc;
14718 
14719     if (n == '0')
14720         {
14721         return 1;
14722         }
14723     else if (n == '1')
14724         {
14725         return 2;
14726         }
14727     else if (n == '2')
14728         {
14729         return 4;
14730         }
14731     else if (n == '3')
14732         {
14733         return 8;
14734         }
14735     else if (n == '4')
14736         {
14737         return 16;
14738         }
14739     else if (n == '5')
14740         {
14741         return 32;
14742         }
14743     else if (n == '6')
14744         {
14745         return 64;
14746         }
14747     else if (n == '7')
14748         {
14749         return 128;
14750         }
14751     else if (n == '8')
14752         {
14753         return 256;
14754         }
14755     else if (n == '9')
14756         {
14757         return 512;
14758         }
14759     else if (n == missingId)
14760         {
14761         return MISSING;
14762         }
14763     else if (n == gapId)
14764         {
14765         return GAP;
14766         }
14767     else
14768         return -1;
14769 }
14770 
14771 
State_CODON(char * state,int code,int division)14772 void State_CODON (char *state, int code, int division)
14773 {
14774     state[0] = StateCode_NUC4(modelParams[division].codonNucs[code][0]);
14775     state[1] = StateCode_NUC4(modelParams[division].codonNucs[code][1]);
14776     state[2] = StateCode_NUC4(modelParams[division].codonNucs[code][2]);
14777     state[3] = '\0';
14778 }
14779 
14780 
State_DOUBLET(char * state,int code)14781 void State_DOUBLET (char *state, int code)
14782 {
14783     state[0] = code/4 + 'A';
14784     state[1] = code%4 + 'A';
14785     state[2] = '\0';
14786 }
14787 
14788 
StateCode_AA(int n)14789 int StateCode_AA (int n)
14790 {
14791     if (n == 0)
14792         return 'A';      /* Ala */
14793     else if (n == 1)
14794         return 'R';      /* Arg */
14795     else if (n == 2)
14796         return 'N';      /* Asn */
14797     else if (n == 3)
14798         return 'D';      /* Asp */
14799     else if (n == 4)
14800         return 'C';      /* Cys */
14801     else if (n == 5)
14802         return 'Q';      /* Gln */
14803     else if (n == 6)
14804         return 'E';      /* Glu */
14805     else if (n == 7)
14806         return 'G';      /* Gly */
14807     else if (n == 8)
14808         return 'H';      /* His */
14809     else if (n == 9)
14810         return 'I';      /* Ile */
14811     else if (n == 10)
14812         return 'L';      /* Leu */
14813     else if (n == 11)
14814         return 'K';      /* Lys */
14815     else if (n == 12)
14816         return 'M';      /* Met */
14817     else if (n == 13)
14818         return 'F';      /* Phe */
14819     else if (n == 14)
14820         return 'P';      /* Pro */
14821     else if (n == 15)
14822         return 'S';      /* Ser */
14823     else if (n == 16)
14824         return 'T';      /* Thr */
14825     else if (n == 17)
14826         return 'W';      /* Trp */
14827     else if (n == 18)
14828         return 'Y';      /* Tyr */
14829     else if (n == 19)
14830         return 'V';      /* Val */
14831     else
14832         return '?';
14833 }
14834 
14835 
StateCode_NUC4(int n)14836 int StateCode_NUC4 (int n)
14837 {
14838     if (n == 0)
14839         return 'A';
14840     else if (n == 1)
14841         return 'C';
14842     else if (n == 2)
14843         return 'G';
14844     else if (n == 3)
14845         return 'T';
14846     else return '?';
14847 }
14848 
14849 
StateCode_Std(int n)14850 int StateCode_Std (int n)
14851 {
14852     if (n <= 9 && n >= 0)
14853         return '0' + n;
14854     else return '?';
14855 }
14856 
14857 
WhatVariableExp(BitsLong exp,char * st)14858 void WhatVariableExp (BitsLong exp, char *st)
14859 {
14860     int         n;
14861 
14862     strcpy (st, "");
14863     n = 0;
14864     if (exp == 0)
14865         strcat(st, " nothing");
14866     else
14867         {
14868         if ((exp & Expecting(COMMAND)) == Expecting(COMMAND))
14869             {
14870             strcat(st, " command");
14871             n++;
14872             }
14873         if ((exp & Expecting(PARAMETER)) == Expecting(PARAMETER))
14874             {
14875             if (n > 0)
14876                 strcat(st, " or");
14877             strcat(st, " parameter");
14878             n++;
14879             }
14880         if ((exp & Expecting(EQUALSIGN)) == Expecting(EQUALSIGN))
14881             {
14882             if (n > 0)
14883                 strcat(st, " or");
14884             strcat(st, " =");
14885             n++;
14886             }
14887         if ((exp & Expecting(COLON)) == Expecting(COLON))
14888             {
14889             if (n > 0)
14890                 strcat(st, " or");
14891             strcat(st, " :");
14892             n++;
14893             }
14894         if ((exp & Expecting(SEMICOLON)) == Expecting(SEMICOLON))
14895             {
14896             if (n > 0)
14897                 strcat(st, " or");
14898             strcat(st, " ;");
14899             n++;
14900             }
14901         if ((exp & Expecting(COMMA)) == Expecting(COMMA))
14902             {
14903             if (n > 0)
14904                 strcat(st, " or");
14905             strcat(st, " ,");
14906             n++;
14907             }
14908         if ((exp & Expecting(POUNDSIGN)) == Expecting(POUNDSIGN))
14909             {
14910             if (n > 0)
14911                 strcat(st, " or");
14912             strcat(st, " #");
14913             n++;
14914             }
14915         if ((exp & Expecting(QUESTIONMARK)) == Expecting(QUESTIONMARK))
14916             {
14917             if (n > 0)
14918                 strcat(st, " or");
14919             strcat(st, " ?");
14920             n++;
14921             }
14922         if ((exp & Expecting(DASH)) == Expecting(DASH))
14923             {
14924             if (n > 0)
14925                 strcat(st, " or");
14926             strcat(st, " -");
14927             n++;
14928             }
14929         if ((exp & Expecting(LEFTPAR)) == Expecting(LEFTPAR))
14930             {
14931             if (n > 0)
14932                 strcat(st, " or");
14933             strcat(st, " (");
14934             n++;
14935             }
14936         if ((exp & Expecting(RIGHTPAR)) == Expecting(RIGHTPAR))
14937             {
14938             if (n > 0)
14939                 strcat(st, " or");
14940             strcat(st, " )");
14941             n++;
14942             }
14943         if ((exp & Expecting(LEFTCOMMENT)) == Expecting(LEFTCOMMENT))
14944             {
14945             if (n > 0)
14946                 strcat(st, " or");
14947             strcat(st, " [");
14948             n++;
14949             }
14950         if ((exp & Expecting(RIGHTCOMMENT)) == Expecting(RIGHTCOMMENT))
14951             {
14952             if (n > 0)
14953                 strcat(st, " or");
14954             strcat(st, " ]");
14955             n++;
14956             }
14957         if ((exp & Expecting(ALPHA)) == Expecting(ALPHA))
14958             {
14959             if (n > 0)
14960                 strcat(st, " or");
14961             strcat(st, " <name>");
14962             n++;
14963             }
14964         if ((exp & Expecting(NUMBER)) == Expecting(NUMBER))
14965             {
14966             if (n > 0)
14967                 strcat(st, " or");
14968             strcat(st, " <number>");
14969             n++;
14970             }
14971         if ((exp & Expecting(RETURNSYMBOL)) == Expecting(RETURNSYMBOL))
14972             {
14973             if (n > 0)
14974                 strcat(st, " or");
14975             strcat(st, " return");
14976             n++;
14977             }
14978         if ((exp & Expecting(ASTERISK)) == Expecting(ASTERISK))
14979             {
14980             if (n > 0)
14981                 strcat(st, " or");
14982             strcat(st, " *");
14983             n++;
14984             }
14985         if ((exp & Expecting(BACKSLASH)) == Expecting(BACKSLASH))
14986             {
14987             if (n > 0)
14988                 strcat(st, " or");
14989             strcat(st, " /");
14990             n++;
14991             }
14992         if ((exp & Expecting(BACKSLASH)) == Expecting(BACKSLASH))
14993             {
14994             if (n > 0)
14995                 strcat(st, " or");
14996             strcat(st, " \\");
14997             n++;
14998             }
14999         if ((exp & Expecting(EXCLAMATIONMARK)) == Expecting(EXCLAMATIONMARK))
15000             {
15001             if (n > 0)
15002                 strcat(st, " or");
15003             strcat(st, " !");
15004             n++;
15005             }
15006         if ((exp & Expecting(PERCENT)) == Expecting(PERCENT))
15007             {
15008             if (n > 0)
15009                 strcat(st, " or");
15010             strcat(st, " %");
15011             n++;
15012             }
15013         if ((exp & Expecting(LEFTCURL)) == Expecting(LEFTCURL))
15014             {
15015             if (n > 0)
15016                 strcat(st, " or");
15017             strcat(st, " {");
15018             n++;
15019             }
15020         if ((exp & Expecting(RIGHTCURL)) == Expecting(RIGHTCURL))
15021             {
15022             if (n > 0)
15023                 strcat(st, " or");
15024             strcat(st, " }");
15025             n++;
15026             }
15027         if ((exp & Expecting(WEIRD)) == Expecting(WEIRD))
15028             {
15029             if (n > 0)
15030                 strcat(st, " or");
15031             strcat(st, " <whatever>");
15032             n++;
15033             }
15034         if ((exp & Expecting(VERTICALBAR)) == Expecting(VERTICALBAR))
15035             {
15036             if (n > 0)
15037                 strcat(st, " or");
15038             strcat(st, " |");
15039             n++;
15040             }
15041         if ((exp & Expecting(UNKNOWN_TOKEN_TYPE)) == Expecting(UNKNOWN_TOKEN_TYPE))
15042             {
15043             if (n > 0)
15044                 strcat(st, " or");
15045             strcat(st, " no clue");
15046             n++;
15047             }
15048         }
15049 }
15050 
15051 
WhichAA(int x)15052 char WhichAA (int x)
15053 {
15054     if (x == 1)
15055         return ('A');
15056     else if (x == 2)
15057         return ('R');
15058     else if (x == 4)
15059         return ('N');
15060     else if (x == 8)
15061         return ('D');
15062     else if (x == 16)
15063         return ('C');
15064     else if (x == 32)
15065         return ('Q');
15066     else if (x == 64)
15067         return ('E');
15068     else if (x == 128)
15069         return ('G');
15070     else if (x == 256)
15071         return ('H');
15072     else if (x == 512)
15073         return ('I');
15074     else if (x == 1024)
15075         return ('L');
15076     else if (x == 2048)
15077         return ('K');
15078     else if (x == 4096)
15079         return ('M');
15080     else if (x == 8192)
15081         return ('F');
15082     else if (x == 16384)
15083         return ('P');
15084     else if (x == 32768)
15085         return ('S');
15086     else if (x == 65536)
15087         return ('T');
15088     else if (x == 131072)
15089         return ('W');
15090     else if (x == 262144)
15091         return ('Y');
15092     else if (x == 524288)
15093         return ('V');
15094     else if (x > 0 && x < 524288)
15095         return ('*');
15096     else if (x == MISSING)
15097         return ('?');
15098     else if (x == GAP)
15099         return ('-');
15100     else
15101         return (' ');
15102 }
15103 
15104 
WhichCont(int x)15105 MrBFlt WhichCont (int x)
15106 {
15107     return ((MrBFlt)(x / 1000.0));
15108 }
15109 
15110 
WhichNuc(int x)15111 char WhichNuc (int x)
15112 {
15113     if (x == 1)
15114         return ('A');
15115     else if (x == 2)
15116         return ('C');
15117     else if (x == 3)
15118         return ('M');
15119     else if (x == 4)
15120         return ('G');
15121     else if (x == 5)
15122         return ('R');
15123     else if (x == 6)
15124         return ('S');
15125     else if (x == 7)
15126         return ('V');
15127     else if (x == 8)
15128         return ('T');
15129     else if (x == 9)
15130         return ('W');
15131     else if (x == 10)
15132         return ('Y');
15133     else if (x == 11)
15134         return ('H');
15135     else if (x == 12)
15136         return ('K');
15137     else if (x == 13)
15138         return ('D');
15139     else if (x == 14)
15140         return ('B');
15141     else if (x == 15)
15142         return ('N');
15143     else if (x == MISSING)
15144         return ('?');
15145     else if (x == GAP)
15146         return ('-');
15147     else
15148         return (' ');
15149 }
15150 
15151 
WhichRes(int x)15152 char WhichRes (int x)
15153 {
15154     if (x == 1)
15155         return ('0');
15156     else if (x == 2)
15157         return ('1');
15158     else if (x == 3)
15159         return ('*');
15160     else if (x == MISSING)
15161         return ('N');
15162     else if (x == GAP)
15163         return ('-');
15164     else
15165         return (' ');
15166 }
15167 
15168 
WhichStand(int x)15169 char WhichStand (int x)
15170 {
15171     if (x == 1)
15172         return ('0');
15173     else if (x == 2)
15174         return ('1');
15175     else if (x == 4)
15176         return ('2');
15177     else if (x == 8)
15178         return ('3');
15179     else if (x == 16)
15180         return ('4');
15181     else if (x == 32)
15182         return ('5');
15183     else if (x == 64)
15184         return ('6');
15185     else if (x == 128)
15186         return ('7');
15187     else if (x == 256)
15188         return ('8');
15189     else if (x == 512)
15190         return ('9');
15191     else if (x > 0 && x < 512)
15192         return ('*');
15193     else if (x == MISSING)
15194         return ('?');
15195     else if (x == GAP)
15196         return ('-');
15197     else
15198         return (' ');
15199 }
15200 
15201