]> git.donarmstrong.com Git - mrbayes.git/blob - src/command.c
import mrbayes
[mrbayes.git] / src / command.c
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 (maxim.teslenko@nrm.se)
22  *
23  *  and by many users (run 'acknowledgments' to see more info)
24  *
25  * This program is free software; you can redistribute it and/or
26  * modify it under the terms of the GNU General Public License
27  * as published by the Free Software Foundation; either version 2
28  * of the License, or (at your option) any later version.
29  *
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  * GNU General Public License for more details (www.gnu.org).
34  *
35  */
36
37 #include "bayes.h"
38 #include "command.h"
39 #include "mbbeagle.h"
40 #include "model.h"
41 #include "mcmc.h"
42 #include "sumpt.h"
43 #include "utils.h"
44 #if defined(__MWERKS__)
45 #include "SIOUX.h"
46 #endif
47
48 const char* const svnRevisionCommandC = "$Rev: 1072 $";   /* Revision keyword which is expended/updated by svn on each commit/update */
49
50 #define NUMCOMMANDS                     62    /* The total number of commands in the program  */
51 #define NUMPARAMS                       276   /* The total number of parameters  */
52 #define PARAM(i, s, f, l)               p->string = s;    \
53                                         p->fp = f;        \
54                                         p->valueList = l; \
55                                         p++;
56 #define HIDE                            0
57 #define SHOW                            1
58
59 /* Debugging options */
60 #undef SHOW_TOKENS
61 #undef ECHO_PROCESSED_COMMANDS
62
63 /* Local function prototypes */
64 int      AddNameSet(NameSet **nameSetList, int numNameSets, char **nameSet, int numNames);
65 int      AddToSet (int i, int j, int k, int id);
66 int      AllocCharacters (void);
67 int      AllocMatrix (void);
68 int      AllocTaxa (void);
69 char     ChangeCase (char c);
70 int      CharacterCode (char ch, int *charCode, int chType);
71 int      CharacterNumber (int charCode, int chType);
72 int      CheckInitialPartitions (void);
73 int      Dex (TreeNode *p);
74 int      DoAbout (void);
75 int      DoAcknowledgments (void);
76 int      DoBeginParm (char *parmName, char *tkn);
77 int      DoBreaks (void);
78 int      DoBreaksParm (char *parmName, char *tkn);
79 int      DoCalibrate (void);
80 int      DoCalibrateParm (char *parmName, char *tkn);
81 int      DoCharset (void);
82 int      DoCharsetParm (char *parmName, char *tkn);
83 int      DoCharStat (void);
84 int      DoCitations (void);
85 int      DoConstraint (void);
86 int      DoConstraintParm (char *parmName, char *tkn);
87 int      DoCtype (void);
88 int      DoCtypeParm (char *parmName, char *tkn);
89 int      DoDelete (void);
90 int      DoDeleteParm (char *parmName, char *tkn);
91 int      DoDimensions (void);
92 int      DoDimensionsParm (char *parmName, char *tkn);
93 int      DoDisclaimer (void);
94 int      DoEndBlock (void);
95 int      DoExecuteParm (char *parmName, char *tkn);
96 int      DoExclude (void);
97 int      DoExcludeParm (char *parmName, char *tkn);
98 int      DoFormat (void);
99 int      DoFormatParm (char *parmName, char *tkn);
100 int      DoHelp (void);
101 int      DoHelpParm (char *parmName, char *tkn);
102 int      DoInclude (void);
103 int      DoIncludeParm (char *parmName, char *tkn);
104 int      DoLog (void);
105 int      DoLogParm (char *parmName, char *tkn);
106 int      DoManual (void);
107 int      DoManualParm (char *parmName, char *tkn);
108 int      DoMatrix (void);
109 int      DoMatrixParm (char *parmName, char *tkn);
110 int      DoNexusParm (char *parmName, char *tkn);
111 int      DoOutgroup (void);
112 int      DoOutgroupParm (char *parmName, char *tkn);
113 int      DoPairs (void);
114 int      DoPairsParm (char *parmName, char *tkn);
115 int      DoPartition (void);
116 int      DoPartitionParm (char *parmName, char *tkn);
117 int      DoRestore (void);
118 int      DoRestoreParm (char *parmName, char *tkn);
119 int      DoSet (void);
120 int      DoSetParm (char *parmName, char *tkn);
121 int      DoShowBeagle (void);
122 int      DoShowMatrix (void);
123 int      DoShowUserTrees (void);
124 int      DoSpeciespartition (void);
125 int      DoSpeciespartitionParm (char *parmName, char *tkn);
126 int      DoTaxaset (void);
127 int      DoTaxasetParm (char *parmName, char *tkn);
128 int      DoTaxaStat (void);
129 int      DoTaxlabels (void);
130 int      DoTaxlabelsParm (char *parmName, char *tkn);
131 int      DoTranslate (void);
132 int      DoTranslateParm (char *parmName, char *tkn);
133 int      DoTree (void);
134 int      DoTreeParm (char *parmName, char *tkn);
135 int      DoUserTree (void);
136 int      DoUserTreeParm (char *parmName, char *tkn);
137 int      DoVersion (void);
138 int      FindValidParam (char *tk, int *numMatches);
139 int      FreeCharacters (void);
140 int      FreeMatrix (void);
141 int      FreeTaxa (void);
142 int      GetNumPartDivisions (int n);
143 int      GetUserHelp (char *helpTkn);
144 int      IsAmbig (int charCode, int dType);
145 int      IsMissing (int charCode, int dType);
146 int      MBResID (char nuc);
147 int      NucID (char nuc);
148 void     PrintSettings (char *command);
149 void     PrintYesNo (int yn, char s[4]);
150 int      ProtID (char aa);
151 int      SetPartition (int part);
152 int      SetSpeciespartition (int part);
153 int      SetTaxaFromTranslateTable (void);
154 int      StandID (char nuc);
155 void     WhatVariableExp (BitsLong exp, char *st);
156 MrBFlt   WhichCont (int x);
157
158 /* globals */
159 int             autoClose;             /* autoclose                                     */
160 int             autoOverwrite;         /* Overwrite or append outputfiles when nowarnings=yes */
161 Calibration     *calibrationPtr;       /* ptr to calibration being set                  */
162 CharInformation *charInfo;             /* holds critical information about characters   */
163 BitsLong        **charSet;             /* holds information about defined charsets      */
164 char            **charSetNames;        /* holds names of character sets                 */
165 Comptree        comptreeParams;        /* holds parameters for comparetree command      */
166 char            **constraintNames;     /* holds names of constraints                    */
167 int             dataType;              /* type of data                                  */
168 Calibration     defaultCalibration;    /* default calibration                           */
169 BitsLong        **definedConstraint;          /* bitfields representing taxa sets of defined constraints                                             */
170 BitsLong        **definedConstraintTwo;       /* bitfields representing second taxa sets of defined constraints (used for PARTIAL constraints)       */
171 BitsLong        **definedConstraintPruned;    /* bitfields representing taxa sets of defined constraints after delited taxa are removed              */
172 BitsLong        **definedConstraintTwoPruned; /* bitfields representing second taxa sets of defined constraints for PARTIAL constraints after delited*/
173                                               /* taxa are removed and for NEGATIVE constraint it contains complements of definedConstraintPruned     */
174 int             echoMB;                /* flag used by Manual to prevent echoing        */
175 BitsLong        expecting;             /* variable denoting expected token type         */
176 int             foundNewLine;          /* whether a new line has been found             */
177 int             inComment;             /* flag for whether input stream is commented    */
178 int             inComparetreeCommand;  /* flag set whenever you enter comparetree cmd   */
179 int             inferAncStates;        /* should ancestral states be inferred (y/n)     */
180 int             inferSiteOmegas;       /* should site omegas be inferred (y/n)          */
181 int             inferSiteRates;        /* should site rates be inferred (y/n)           */
182 int             inMrbayesBlock;        /* flag for whether we are in a mrbayes block    */
183 int             inSumtCommand;         /* flag set whenever you enter sumt cmd          */
184 int             inTreesBlock;          /* flag for whether we are in a trees block      */
185 int             inValidCommand;        /* a useful flag set whenever you enter a cmd    */
186 int             isInAmbig, isInPoly;   /* flags whether we are within () or {}          */
187 int             isTaxsetDef;           /* is a taxon set defined                        */
188 int             isTranslateDef;        /* is a translation block defined                */
189 int             isTranslateDiff;       /* is translate different from current taxaset?  */
190 char            logFileName[100];      /* name of the log file                          */
191 int             logToFile;             /* should screen output be logged to a file      */
192 FILE            *logFileFp;            /* file pointer to log file                      */
193 int             longIntegerSize;       /* size of an unsigned integer                   */
194 char            manFileName[100];      /* name of the file for the command help info    */
195 int             *matrix;               /* matrix containing original data               */
196 int             matrixHasPoly;         /* flag for whether matrix has polymorphisms     */
197 int             memAllocs[NUM_ALLOCS]; /* allocated memory flags                        */
198 int             mode;                  /* mode of program (interactive/noninteractive)  */
199 Calibration     *nodeCalibration;      /* holds information about node calibrations     */
200 int             noWarn;                /* no warnings on overwriting files              */
201 int             numChar;               /* number of characters in character matrix      */
202 int             numCharSets;           /* number of character sets                      */
203 int             numComments;           /* counts how deeply nested a comment is         */
204 int             numDefinedConstraints; /* number of constraints defined                 */
205 int             numDefinedPartitions;  /* number of partitions defined                  */
206 int             numDefinedSpeciespartitions;  /* number of speciespartitions defined    */
207 int             numNamedTaxa;          /* number of named taxa during parsing of cmd    */
208 int             numOpenExeFiles;       /* number of execute files open                  */
209 int             numSpecies;            /* number of species in current speciespartition */
210 int             numTaxa;               /* number of taxa in character matrix            */
211 int             numTaxaSets;           /* number of taxa sets                           */
212 int             numTranslates;         /* number of taxa in active translate block      */
213 int             outGroupNum;           /* number of outgroup taxon                      */
214 ParmInfo        paramTable[NUMPARAMS]; /* information on parameters                     */
215 char            **partitionNames;      /* hold names of partitions (first is "default") */
216 int             **partitionId;         /* holds information about defined partitions    */
217 int             partitionNum;          /* index of current partition                    */
218 Plot            plotParams;            /* holds parameters for plot command             */
219 int             precision;             /* precision of samples and summary stats        */
220 int             quitOnError;           /* quit on error?                                */
221 int             replaceLogFile;        /* should logfile be replace/appended to         */
222 int             scientific;            /* use scientific format for samples ?           */
223 char            spacer[10];            /* holds blanks for printing indentations        */
224 NameSet         *speciesNameSets;      /* hold species name sets, one for each speciespartition     */
225 int             **speciespartitionId;  /* holds info about defined speciespartitions    */
226 char            **speciespartitionNames;    /* hold names of speciespartitions (first is "default") */
227 int             speciespartitionNum;   /* index of current speciespartition             */
228 Sump            sumpParams;            /* holds parameters for sump command             */
229 Sumt            sumtParams;            /* holds parameters for sumt command             */
230 Sumss           sumssParams;           /* holds parameters for sumss command            */
231 TaxaInformation *taxaInfo;             /* holds critical information about taxa         */
232 char            **taxaNames;           /* holds name of taxa                            */
233 BitsLong        **taxaSet;             /* holds information about defined taxasets      */
234 char            **taxaSetNames;        /* holds names of taxa sets                      */
235 int             *tempActiveConstraints;/* temporarily holds active constraints size allcated        */
236 enum ConstraintType  *definedConstraintsType;  /* Store type of constraint              */
237 int             *tempSet;              /* temporarily holds defined set                 */
238 int             *tempSetNeg;           /* holds bitset of negative set of taxa for partial constraint*/
239 int             theAmbigChar;          /* int containing ambiguous character            */
240 Calibration     *tipCalibration;       /* holds information about node calibrations     */
241 char            **transFrom;           /* translation block information                 */
242 char            **transTo;             /* translation block information                 */
243 int             userBrlensDef;         /* are the branch lengths on user tree defined   */
244
245 #if defined (BEAGLE_ENABLED)
246 int             tryToUseBEAGLE;        /* try to use the BEAGLE library                 */
247 int             beagleScalingScheme;   /* BEAGLE dynamic scaling                        */
248 int             beagleScalingFrequency;/* BEAGLE dynamic scaling frequency              */
249 long            beagleFlags;           /* BEAGLE required resource flags                */
250 int             beagleResourceNumber;  /* BEAGLE resource number                        */
251 int             *beagleResource;       /* BEAGLE resource choice list                   */
252 int             beagleResourceCount;   /* BEAGLE resource choice list length            */
253 int             beagleInstanceCount;   /* total number of BEAGLE instances              */
254 #endif
255
256 #if defined (THREADS_ENABLED)
257 int             tryToUseThreads;       /* try to use pthreads with BEAGLE library       */
258 #endif
259
260 /* local (to this file) */
261 char            *tokenP, token[CMD_STRING_LENGTH], *cmdStr=NULL;
262 Calibration     defaultCalibration = {
263                     "Unconstrained",      /* name */
264                     unconstrained,        /* prior */
265                     { -1.0, -1.0, -1.0 }, /* priorParams */
266                     NULL,                 /* LnPriorProb */
267                     NULL,                 /* LnPriorRatio */
268                     -1.0,                 /* min */
269                     -1.0                  /* max */
270                 };
271
272 CmdType     commands[] =
273             {
274             /*  Information on commands initialization:
275              
276                     1 = Command number (cmdNumber)
277                     2 = Command name (string)
278                     3 = Special command (YES/NO) (specialCmd) 
279                     4 = Pointer to finishing function (fp)
280                     5 = Number of valid parameters (numParms)
281                     6 = List of valid parameters (parmList) 
282                     7 = Expecting (2^TokenType) (expect) (PARAMETER = 4; SEMICOLON = 32; ALPHA = 16384; 
283                         ALPHA | QUESTIONMARK | DASH | NUMBER | ASTERISK | EXCLAMATIONMARK | PERCENT | WEIRD | SEMICOLON = 11715360;
284                         ALPHA | QUESTIONMARK | DASH | NUMBER | ASTERISK | EXCLAMATIONMARK | PERCENT | WEIRD | VERTICALBAR | SEMICOLON | LEFTPAR | RIGHTPAR | LEFTCURL | RIGHTCURL = 649252640;
285                         PARAMETER | SEMICOLON = 36; NUMBER | ALPHA = 49152; ALPHA | SEMICOLON = 16416; EQUALSIGN = 8; NUMBER = 32768)
286                     8 = Description of the command (cmdDescription)
287                     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)
288                    10 = Should the command be shown when "help" is typed (hiding).
289              
290               #1                 #2   #3                 #4  #5                                                                                                #6        #7                                                            #8       #9   #10
291              -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
292             {  0,               "#",  NO,              NULL,  1,                                                                                              {0},        4,                                                           "", IN_FILE, HIDE },
293             {  1,           "About",  NO,           DoAbout,  0,                                                                                             {-1},       32,                                      "Describes the program",  IN_CMD, SHOW },
294             {  2, "Acknowledgments",  NO, DoAcknowledgments,  0,                                                                                             {-1},       32,                              "Shows program acknowledgments",  IN_CMD, SHOW },
295             {  3,           "Begin",  NO,              NULL,  6,                                                                              {1,2,3,201,226,227},        4,                         "Denotes beginning of block in file", IN_FILE, SHOW },
296             {  4,       "Calibrate",  NO,       DoCalibrate,  1,                                                                                            {119},        4,               "Assigns dates to terminals or interior nodes",  IN_CMD, SHOW },
297             {  5,         "Charset",  NO,         DoCharset,  1,                                                                                             {15},        4,                          "Assigns a group of sites to a set",  IN_CMD, SHOW },
298             {  6,        "Charstat",  NO,        DoCharStat,  0,                                                                                             {-1},       32,                                 "Shows status of characters",  IN_CMD, SHOW },
299             {  7,       "Citations",  NO,       DoCitations,  0,                                                                                             {-1},       32,                   "Citation of program, models, and methods",  IN_CMD, SHOW },
300             {  8,     "Comparetree",  NO,     DoCompareTree,  7,                                                                    {127,128,129,130,221,222,223},       36,                     "Compares the trees from two tree files",  IN_CMD, SHOW },
301             {  9,      "Constraint",  NO,      DoConstraint,  1,                                                                                             {66},        4,                      "Defines a constraint on tree topology",  IN_CMD, SHOW },
302             { 10,           "Ctype",  NO,           DoCtype,  1,                                                                                             {65},        4,                        "Assigns ordering for the characters",  IN_CMD, SHOW },
303             { 11,      "Databreaks", YES,          DoBreaks,  1,                                                                                             {93},    32768,           "Defines data breaks for autodiscrete gamma model",  IN_CMD, SHOW },
304             { 12,          "Delete", YES,          DoDelete,  1,                                                                                             {47},    49152,                             "Deletes taxa from the analysis",  IN_CMD, SHOW },
305             { 13,      "Dimensions",  NO,      DoDimensions,  2,                                                                                            {4,5},        4,                           "Defines size of character matrix", IN_FILE, SHOW },
306             { 14,      "Disclaimer",  NO,      DoDisclaimer,  0,                                                                                             {-1},       32,                               "Describes program disclaimer",  IN_CMD, SHOW },
307             { 15,             "End",  NO,        DoEndBlock,  0,                                                                                             {-1},       32,                             "Denotes end of a block in file", IN_FILE, SHOW },
308             { 16,        "Endblock",  NO,        DoEndBlock,  0,                                                                                             {-1},       32,                 "Alternative way of denoting end of a block", IN_FILE, SHOW },
309             { 17,         "Exclude", YES,         DoExclude,  1,                                                                                             {45},    49152,                           "Excludes sites from the analysis",  IN_CMD, SHOW },
310             { 18,         "Execute", YES,         DoExecute,  1,                                                                                             {12},    16384,                                            "Executes a file",  IN_CMD, SHOW },
311             { 19,          "Format",  NO,          DoFormat,  7,                                                                             {6,7,8,9,10,219,220},        4,                     "Defines character format in data block", IN_FILE, SHOW },
312             { 20,            "Help", YES,            DoHelp,  1,                                                                                             {50},    16416,                  "Provides detailed description of commands",  IN_CMD, SHOW },
313             { 21,         "Include", YES,         DoInclude,  1,                                                                                             {46},    49152,                                             "Includes sites",  IN_CMD, SHOW },
314             { 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,
315                                                                                                                                                      270,273,274},        4,               "Links parameters across character partitions",  IN_CMD, SHOW },
316             { 23,             "Log",  NO,             DoLog,  5,                                                                                 {85,86,87,88,89},        4,                               "Logs screen output to a file",  IN_CMD, SHOW },
317             { 24,            "Lset",  NO,            DoLset, 16,                                             {28,29,30,31,32,33,34,40,51,52,53,90,91,131,188,189},        4,                "Sets the parameters of the likelihood model",  IN_CMD, SHOW },
318             { 25,          "Manual",  NO,          DoManual,  1,                                                                                            {126},       36,                  "Prints a command reference to a text file",  IN_CMD, SHOW },
319             { 26,          "Matrix", YES,          DoMatrix,  1,                                                                                             {11},649252640,                 "Defines matrix of characters in data block", IN_FILE, SHOW },
320             { 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,
321                                                                                      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 },
322             { 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,
323                                                                                      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 },
324             { 29,        "Outgroup", YES,        DoOutgroup,  1,                                                                                             {78},    49152,                                     "Changes outgroup taxon",  IN_CMD, SHOW },
325             { 30,           "Pairs", YES,           DoPairs,  1,                                                                                             {92},    32768,        "Defines nucleotide pairs (doublets) for stem models",  IN_CMD, SHOW },
326             { 31,       "Partition",  NO,       DoPartition,  1,                                                                                             {16},        4,                              "Assigns a character partition",  IN_CMD, SHOW },
327             { 32,            "Plot",  NO,            DoPlot,  6,                                                                        {106,107,108,109,224,225},       36,                        "Plots parameters from MCMC analysis",  IN_CMD, SHOW },
328             { 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,
329                                                                                                  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 },
330             { 34,         "Propset",  NO,         DoPropset,  1,                                                                                            {186},        4,          "Sets proposal probabilities and tuning parameters",  IN_CMD, SHOW },
331             { 35,            "Quit",  NO,            DoQuit,  0,                                                                                             {-1},       32,                                          "Quits the program",  IN_CMD, SHOW },
332             { 36,          "Report",  NO,          DoReport,  9,                                                            {122,123,124,125,134,135,136,192,217},        4,                 "Controls how model parameters are reported",  IN_CMD, SHOW },
333             { 37,         "Restore", YES,         DoRestore,  1,                                                                                             {48},    49152,                                              "Restores taxa",  IN_CMD, SHOW },
334             { 38,             "Set",  NO,             DoSet, 22,           {13,14,94,145,170,171,179,181,182,216,229,233,234,235,236,237,238,239,240,245,268,275},        4,      "Sets run conditions and defines active data partition",  IN_CMD, SHOW },
335             { 39,      "Showbeagle",  NO,      DoShowBeagle,  0,                                                                                             {-1},       32,                            "Show available BEAGLE resources",  IN_CMD, SHOW },
336             { 40,      "Showmatrix",  NO,      DoShowMatrix,  0,                                                                                             {-1},       32,                             "Shows current character matrix",  IN_CMD, SHOW },
337             { 41,   "Showmcmctrees",  NO,   DoShowMcmcTrees,  0,                                                                                             {-1},       32,                          "Shows trees used in mcmc analysis",  IN_CMD, SHOW },
338             { 42,       "Showmodel",  NO,       DoShowModel,  0,                                                                                             {-1},       32,                                       "Shows model settings",  IN_CMD, SHOW },
339             { 43,       "Showmoves",  NO,       DoShowMoves,  1,                                                                                            {180},       36,                              "Shows moves for current model",  IN_CMD, SHOW },
340             { 44,      "Showparams",  NO,      DoShowParams,  0,                                                                                             {-1},       32,                          "Shows parameters in current model",  IN_CMD, SHOW },
341             { 45,   "Showusertrees",  NO,   DoShowUserTrees,  0,                                                                                             {-1},       32,                                   "Shows user-defined trees",  IN_CMD, SHOW },
342             { 46,"Speciespartition",  NO,DoSpeciespartition,  1,                                                                                            {244},        4,                   "Defines a partition of tips into species",  IN_CMD, SHOW },
343             { 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,
344                                                                      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 },
345             { 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,
346                                                                      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 },
347             { 49,       "Startvals",  NO,       DoStartvals,  1,                                                                                            {187},        4,                         "Sets starting values of parameters",  IN_CMD, SHOW },
348             { 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 },
349             { 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 },
350             { 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 },
351             { 53,        "Taxastat",  NO,        DoTaxaStat,  0,                                                                                             {-1},       32,                                       "Shows status of taxa",  IN_CMD, SHOW },
352             { 54,          "Taxset",  NO,         DoTaxaset,  1,                                                                                             {49},        4,                           "Assigns a group of taxa to a set",  IN_CMD, SHOW },
353             { 55,       "Taxlabels", YES,       DoTaxlabels,  1,                                                                                            {228},    49152,                                       "Defines taxon labels", IN_FILE, SHOW },
354             { 56,       "Translate", YES,       DoTranslate,  1,                                                                                             {83},    49152,                         "Defines alternative names for taxa", IN_FILE, SHOW },
355             { 57,            "Tree",  NO,            DoTree,  1,                                                                                             {79},        4,                                             "Defines a tree", IN_FILE, SHOW },
356             { 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,
357                                                                                                                                                      270,273,274},        4,             "Unlinks parameters across character partitions",  IN_CMD, SHOW },
358             { 59,        "Usertree", YES,        DoUserTree,  1,                                                                                            {203},        8,                                 "Defines a single user tree",  IN_CMD, HIDE },
359             { 60,         "Version",  NO,         DoVersion,  0,                                                                                             {-1},       32,                                      "Shows program version",  IN_CMD, SHOW },
360             { 61,      "Compareref",  NO,     DoCompRefTree,  7,                                                                    {127,128,129,130,221,222,223},       36,                     "Compares the tree to the reference trees",  IN_CMD, HIDE },
361             /* NOTE: If you add a command here, make certain to change NUMCOMMANDS (above, in this file) appropriately! */
362             { 999,             NULL,  NO,              NULL,  0,                                                                                             {-1},       32,                                                           "",  IN_CMD, HIDE }  
363             };
364 int                 inDataBlock, inForeignBlock, isInterleaved, isFirstMatrixRead, isFirstInterleavedBlock, 
365                     taxonCount, fromI, toJ, everyK, foundDash, foundSlash, foundFirst, isMixed, whichPartition,
366                     isNegative, numDivisions, charOrdering, foundExp, foundColon, isFirstNode, nextAvailableNode,
367                     pairId, firstPair, inTaxaBlock, inCharactersBlock, foundEqual;
368 char                gapId, missingId, matchId, tempSetName[100], **tempNames;
369 CmdType             *commandPtr; /* Points to the commands array entry which corresponds to currently processed command */
370 ParmInfoPtr         paramPtr;    /* Points to paramTable table array entry which corresponds to currently processed parameter of current command */
371 TreeNode            *pPtr, *qPtr;
372
373 enum ConstraintType     consrtainType; /* Used only in processing of constraine command to indicate what is the type of constrain */
374
375
376 int AddToGivenSet (int i, int j, int k, int id, int *Set)
377 {
378     int     m, n;
379     
380     if (id <= 0)
381         {
382         MrBayesPrint ("%s   The id for a temporary set should be greater than 0\n", spacer);
383         return (ERROR);
384         }
385     
386     if (i < 0 && j < 0)
387         return (ERROR);
388     else if (i < 0 && j >= 0)
389         return (ERROR);
390     else if (i >= 0 && j < 0)
391         {
392         if (k >= 0)
393             return (ERROR);
394         else
395             {
396             if (Set[i] != 0)
397                 {
398                 MrBayesPrint ("%s   Character %d defined more than once\n", spacer, i+1);
399                 return (ERROR);
400                 }
401             Set[i] = id;
402             }
403         }
404     else if (i >= 0 && j >= 0)
405         {
406         if (k < 0)
407             {
408             for (m=i; m<=j; m++)
409                 {
410                 if (Set[m] != 0)
411                     {
412                     MrBayesPrint ("%s   Character %d defined more than once\n", spacer, m+1);
413                     return (ERROR);
414                     }
415                 Set[m] = id;
416                 }
417             }
418         else
419             {
420             n = k;
421             for (m=i; m<=j; m++)    
422                 {
423                 if (n % k == 0)
424                     {
425                     if (Set[m] != 0)
426                         {
427                         MrBayesPrint ("%s   Character %d defined more than once\n", spacer, m+1);
428                         return (ERROR);
429                         }
430                     Set[m] = id;
431                     }
432                 n++;
433                 }
434             }
435         }
436
437     return (NO_ERROR);
438     
439 }
440
441
442 int AddToSet (int i, int j, int k, int id)
443 {
444     return AddToGivenSet (i, j, k,id, tempSet);
445 }
446
447
448 /* AddNameSet: Push a name set onto the end of a list of name sets, with reallocation
449       of list to hold the extra element. The calling function needs to keep track of
450       the counter holding the length of the list. */
451 int AddNameSet (NameSet **nameSetList, int numNameSets, char **nameSet, int numNames)
452 {
453     int     i;
454
455     (*nameSetList) = (NameSet*) SafeRealloc ((void*)(*nameSetList), ((size_t)numNameSets+1)*sizeof(NameSet));
456
457     (*nameSetList)[numNameSets].names    = NULL;
458     (*nameSetList)[numNameSets].numNames = numNames;
459
460     for (i=0; i<numNames; i++)
461         AddString(&((*nameSetList)[numNameSets].names), i, nameSet[i]);
462     
463     return NO_ERROR;
464 }
465
466
467 /* AddString: Push a string onto the end of a list, with reallocation of list
468       to hold the extra element. The calling function needs to keep track of
469       the counter holding the length of the list. */
470 int AddString (char ***list, int len, char *token)
471 {
472     (*list) = (char **) SafeRealloc ((void *)(*list), ((size_t)len+1)*sizeof(char*));
473     if (!(*list))
474         return ERROR;
475
476     (*list)[len] = (char *) SafeCalloc ((strlen(token)+1), sizeof(char));
477     if (!(*list)[len])
478         return ERROR;
479
480     strcpy ((*list)[len], token);
481     
482     return NO_ERROR;
483 }
484
485
486 int AllocCharacters (void)
487 {
488     int     i, tempSetSize;
489
490     if (memAllocs[ALLOC_MATRIX] == YES)
491         goto errorExit;
492     matrix = (int *) SafeMalloc((size_t)numTaxa * (size_t)numChar * sizeof(int));
493     if (!matrix)
494         {
495         MrBayesPrint ("%s   Problem allocating matrix (%d)\n", spacer, numTaxa * numChar * sizeof(int));
496         goto errorExit;
497         }
498     for (i=0; i<numTaxa * numChar; i++)
499         matrix[i] = 0;
500     memAllocs[ALLOC_MATRIX] = YES;
501
502     if (memAllocs[ALLOC_CHARINFO] == YES)
503         goto errorExit;
504     charInfo = (CharInformation *) SafeMalloc ((size_t)numChar * sizeof(CharInformation));
505     if (!charInfo)
506         {
507         MrBayesPrint ("%s   Problem allocating charInfo (%d)\n", spacer, numChar * sizeof(CharInformation));
508         goto errorExit;
509         }
510     for (i=0; i<numChar; i++)
511         {
512         charInfo[i].isExcluded = NO;
513         charInfo[i].numStates = 0;
514         charInfo[i].charType = 0;
515         charInfo[i].isMissAmbig = NO;
516         charInfo[i].ctype = UNORD;
517         charInfo[i].charId = 0;
518         charInfo[i].pairsId = 0;
519         charInfo[i].bigBreakAfter = NO;
520         }
521     memAllocs[ALLOC_CHARINFO] = YES;
522
523     if (memAllocs[ALLOC_CHARSETS] == YES)
524         goto errorExit;
525     charSetNames = NULL;
526     charSet = NULL;
527     numCharSets = 0;
528     memAllocs[ALLOC_CHARSETS] = YES;    /* safe to do free */
529
530     if (memAllocs[ALLOC_PARTITIONS] == YES)
531         goto errorExit;
532     partitionNames = NULL;
533     partitionId = (int**) SafeMalloc ((size_t)numChar * sizeof(int*));
534     for (i=0; i<numChar; i++)
535         partitionId[i] = (int *) SafeMalloc (sizeof(int));
536     numDefinedPartitions = 0;   /* number of defined partitions */
537     memAllocs[ALLOC_PARTITIONS] = YES;  /* safe to do free */
538
539     if (memAllocs[ALLOC_PARTITIONVARS] == YES)
540         goto errorExit;
541     numVars           = NULL;
542     tempLinkUnlinkVec = NULL;
543     activeParts       = NULL;
544     tempLinkUnlinkVec = NULL;
545     tempNum           = NULL;
546     linkTable[0]      = NULL;
547     tempLinkUnlink[0] = NULL;
548     for (i=0; i<NUM_LINKED; i++)
549         {
550         linkTable[i]      = NULL;
551         tempLinkUnlink[i] = NULL;
552         activeParams[i]   = NULL;
553         }
554     memAllocs[ALLOC_PARTITIONVARS] = YES;
555
556     if (memAllocs[ALLOC_TMPSET] == NO)
557         goto errorExit;
558     if (numChar > numTaxa)
559         tempSetSize = numChar;
560     else
561         tempSetSize = numTaxa;
562     tempSet = (int *) SafeRealloc ((void *)tempSet, (size_t)tempSetSize * sizeof(int));
563     tempSetNeg = (int *) SafeRealloc ((void *)tempSetNeg, (size_t)tempSetSize * sizeof(int));
564     if (!tempSet || !tempSetNeg)
565         {
566         MrBayesPrint ("%s   Problem reallocating tempSet (%d)\n", spacer, tempSetSize * sizeof(int));
567         goto errorExit;
568         }
569
570     MrBayesPrint ("%s   Allocated matrix\n", spacer);
571     return (NO_ERROR);
572
573     errorExit:
574         MrBayesPrint ("%s   Problem allocating matrix\n", spacer);
575         FreeMatrix();
576         return (ERROR);
577 }
578
579
580 int AllocMatrix (void)
581 {
582     if (memAllocs[ALLOC_TAXA] == NO && AllocTaxa() == ERROR)
583         return ERROR;
584     else
585         return (AllocCharacters());
586 }
587
588
589 int AllocTaxa (void)
590 {
591     int i;
592
593     if (defTaxa==NO)
594         {
595         MrBayesPrint ("%s   Number of taxa not defined\n", spacer);
596         return (ERROR);
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     taxaNames = NULL;   /* This variable is allocated in AddString */
608     taxaInfo = (TaxaInformation *) SafeMalloc ((size_t)numTaxa * sizeof(TaxaInformation));
609     if (!taxaInfo)
610         {
611         goto errorExit;
612         }
613     tipCalibration = (Calibration *) SafeMalloc ((size_t)numTaxa * sizeof(Calibration));
614     if (!tipCalibration)
615         {
616         free (taxaInfo);
617         taxaInfo = NULL;
618         goto errorExit;
619         }
620     for (i=0; i<numTaxa; i++)
621         {
622         taxaInfo[i].isDeleted = NO;
623         taxaInfo[i].charCount = 0;
624         }
625     memAllocs[ALLOC_TAXA] = YES;
626
627     /* taxa sets */
628     if (memAllocs[ALLOC_TAXASETS] == YES)
629         goto errorExit;
630     taxaSetNames = NULL;
631     taxaSet = NULL;
632     numTaxaSets = 0;
633     memAllocs[ALLOC_TAXASETS] = YES;    /* safe to free */
634
635     /* species partitions; allocate space and set default species partition */
636     if (memAllocs[ALLOC_SPECIESPARTITIONS] == YES)
637         goto errorExit;
638     speciespartitionNames = NULL;
639     speciesNameSets = NULL;
640     speciespartitionId = (int**) SafeMalloc ((size_t)numTaxa * sizeof(int*));
641     for (i=0; i<numTaxa; i++)
642         {
643         speciespartitionId[i] = (int *) SafeMalloc (sizeof(int));
644         speciespartitionId[i][0] = i + 1;   /* 1-based taxon index, do not ask me why */
645         }
646     numDefinedSpeciespartitions = 0;   /* number of defined species partitions */
647     memAllocs[ALLOC_SPECIESPARTITIONS] = YES;  /* safe to do free */
648
649     /* constraints */
650     if (memAllocs[ALLOC_CONSTRAINTS] == YES)
651         goto errorExit;
652     constraintNames = NULL;
653     definedConstraintsType = NULL; 
654     definedConstraint = NULL;
655     definedConstraintTwo = NULL;
656     definedConstraintPruned = NULL;
657     definedConstraintTwoPruned = NULL;   
658     numDefinedConstraints = 0;
659     tempActiveConstraints = NULL;
660     memAllocs[ALLOC_CONSTRAINTS] = YES;     /* safe to free */
661
662     /* translate table */
663     transFrom = NULL;
664     transTo = NULL;
665     numTranslates = 0;
666
667     /* tempSet */
668     if (memAllocs[ALLOC_TMPSET] == YES)
669         goto errorExit;
670     tempSet = (int *) SafeMalloc ((size_t)numTaxa * sizeof(int));
671     tempSetNeg = (int *) SafeMalloc ((size_t)numTaxa * sizeof(int));
672     if (!tempSet || !tempSetNeg)
673         goto errorExit;
674     memAllocs[ALLOC_TMPSET] = YES;
675
676     /* make sure previous user trees are freed */
677     if (numUserTrees > 0)
678         {
679         MrBayesPrint ("%s   Previous user trees not freed\n", spacer);
680         goto errorExit;
681         }
682
683     MrBayesPrint ("%s   Allocated taxon set\n", spacer);
684     return NO_ERROR;
685
686 errorExit:
687     MrBayesPrint ("%s   Problem allocating taxon set\n", spacer);
688     FreeTaxa();
689     return ERROR;
690 }
691
692
693 char ChangeCase (char c)
694 {
695     int     x;
696     
697     x = tolower(c);
698     return (x);
699 }
700
701
702 int CharacterCode (char ch, int *charCode, int chType)
703 {
704     if (chType == DNA || chType == RNA)
705         {
706         if ((*charCode = NucID (ch)) == -1)
707             {
708             MrBayesPrint ("%s   Unrecognized DNA/RNA character '%c'\n", spacer, ch);
709             return (ERROR);
710             }
711         }
712     else if (chType == PROTEIN)
713         {
714         if ((*charCode = ProtID (ch)) == -1)
715             {
716             MrBayesPrint ("%s   Unrecognized Protein character '%c'\n", spacer, ch);
717             return (ERROR);
718             }
719         }
720     else if (chType == RESTRICTION)
721         {
722         if ((*charCode = MBResID (ch)) == -1)
723             {
724             MrBayesPrint ("%s   Unrecognized Restriction character '%c'\n", spacer, ch);
725             return (ERROR);
726             }
727         }
728     else if (chType == STANDARD)
729         {
730         if ((*charCode = StandID (ch)) == -1)
731             {
732             MrBayesPrint ("%s   Unrecognized Standard character '%c'\n", spacer, ch);
733             return (ERROR);
734             }
735         }
736     else if (chType == CONTINUOUS)
737         {
738         MrBayesPrint ("%s   CharacterCode function cannot check continuous characters\n", spacer);
739         }
740     else
741         {
742         MrBayesPrint ("%s   Unrecognized character type (%d)\n", spacer, chType);
743         return (ERROR);
744         }
745         
746     return (NO_ERROR);
747 }
748
749
750 int CharacterNumber (int charCode, int chType)
751 {
752     int i, x = charCode;
753     
754     if (chType == CONTINUOUS)
755         return 0;
756
757     for (i=0; x!=0; i++)
758         x >>= 1;
759
760     return (i);
761 }
762
763
764 int CheckInitialPartitions (void)
765 {
766     int     i;
767     
768     for (i=0; i<numChar; i++)
769         {
770         if (partitionId[i][0] <= 0 || partitionId[i][0] > numDivisions)
771             {
772             MrBayesPrint ("%s   The partition for site %d is incorrect\n", spacer, i+1); 
773             return (ERROR);
774             }
775         }
776         
777     return (NO_ERROR);
778 }
779
780
781 int CheckStringValidity (char *s)
782 {
783     int         i, numUnknownChars, tempNumComments, tempInComment;
784     char        temp[100];
785
786     i = 0;
787     numUnknownChars = 0;
788     tempNumComments = numComments;
789     tempInComment = inComment;
790
791     while (s[i] != '\0')
792         {
793         if (tempInComment == NO)
794             {
795             if (!IsIn(s[i],"=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789.;:,#()[]?-*/'\\'!%\"&~+^$@|{}`>< "))
796                 {
797                 if (IsWhite(s[i]) == 1 || IsWhite(s[i]) == 2)
798                     {
799                     
800                     }
801                 else
802                     {
803                     if (commandPtr == NULL) 
804                         return (ERROR);
805                     MrBayesPrint ("%s   Unknown character \"%c\" (ASCII code %d)\n", spacer, s[i], s[i]);
806                     if (!strcmp(commandPtr->string,"Matrix"))
807                         {
808                         if (foundNewLine == NO)
809                             {
810                             MrBayesPrint ("%s   The error is in character %d for taxon %s\n", spacer, taxaInfo[taxonCount-1].charCount+i+1, "???"); /* bug? */
811                             }
812                         else
813                             {
814                             if (taxonCount == 0)
815                                 MrBayesPrint ("%s   The error is in the first taxon name\n", spacer);
816                             else
817                                 {
818                                 strcpy(temp, taxaNames[taxonCount]);
819                                 if (isInterleaved == NO)
820                                     MrBayesPrint ("%s   The error is in the name of the taxon following taxon %s\n", spacer, temp);
821                                 else
822                                     {
823                                     MrBayesPrint ("%s   The error is in the name of the taxon following taxon %s\n", spacer, temp);
824                                     MrBayesPrint ("%s   in one of the interleaved data blocks\n", spacer);
825                                     }
826                                 }
827                             }
828                         }
829                     else if (!strcmp(commandPtr->string,"Execute"))
830                         {
831                         MrBayesPrint ("%s   Assuming irrelevant characters at beginning of file; processing continues\n", spacer);
832                         return (NO_ERROR);
833                         }
834                     return (ERROR);
835                     }
836                 }
837             if (s[i]=='[')
838                 {
839                 tempInComment = YES;
840                 tempNumComments++;
841                 }
842             }
843         else if (tempInComment == YES)
844             {
845             if (s[i]==']')
846                 {
847                 tempNumComments--;
848                 if (tempNumComments == 0)
849                     tempInComment = NO;
850                 }
851             }
852         i++;
853         }
854         
855     if (numUnknownChars > 0)
856         return (ERROR);
857     else
858         return (NO_ERROR);
859 }
860
861
862 /* CheckString: This function simply checks a vector of strings for a match against token.
863           Upon return, matchIndex contains the index of the matched string. An
864           ERROR is returned if there are no matches.  */
865 int CheckString (char **list, int len, char *token, int *matchIndex)
866 {
867     int         i;      
868         
869     *matchIndex = -1;
870     for (i=0; i<len; i++)
871         {
872         if (StrCmpCaseInsensitive(token,list[i]) == 0)
873             {
874             *matchIndex = i;
875             return (NO_ERROR);
876             }
877         }
878
879     return (ERROR); 
880 }
881
882
883 int Dex (TreeNode *p)
884 {
885     return (p == NULL) ? -1 : p->index;
886 }
887
888
889 int DoAbout (void)
890 {
891     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
892     MrBayesPrint ("   About the program                                                             \n");
893     MrBayesPrint ("                                                                                 \n");
894     MrBayesPrint ("   MrBayes is a program for the Bayesian estimation of phylogeny. Bayesian       \n");
895     MrBayesPrint ("   inference of phylogeny is based upon the posterior probability distribution   \n");
896     MrBayesPrint ("   of trees. Trees are labelled T1, T2, ..., Tn, where n is the number of        \n");
897     MrBayesPrint ("   possible trees. The posterior probability of the i-th tree is calculated      \n");
898     MrBayesPrint ("   using Bayes\'s formula as                                                     \n");
899     MrBayesPrint ("                                                                                 \n");
900     MrBayesPrint ("      Pr[Ti | X] = Pr[X | Ti] X Pr[Ti] / Pr[X]                                   \n");
901     MrBayesPrint ("                                                                                 \n");
902     MrBayesPrint ("   where X is a character matrix. Here, \"Pr[Ti | X]\" is the posterior          \n");
903     MrBayesPrint ("   probability of the i-th tree, \"Pr[X | Ti]\" is the likelihood of the         \n");
904     MrBayesPrint ("   i-th tree, and \"Pr[Ti]\" is the prior probability of the i-th tree. The      \n");
905     MrBayesPrint ("   denominator of Bayes\'s formula (\"Pr[X]\") is a normalizing constant that    \n");
906     MrBayesPrint ("   involves a summation over all possible trees. The likelihood, as described    \n");
907     MrBayesPrint ("   above, cannot be calculated with knowledge of only the tree\'s topology. You  \n");
908     MrBayesPrint ("   also need to have information on the lenths of the branches and on the        \n");
909     MrBayesPrint ("   mechanism of character change. Hence, the likelihood (\"Pr[X | Ti]\")         \n");
910     MrBayesPrint ("   involves a multidimensional integral over all possible combinations of        \n");
911     MrBayesPrint ("   branch lengths and substitution model parameters.                             \n");
912     MrBayesPrint ("                                                                                 \n");
913     MrBayesPrint ("   In practice, it is impossible to calculate the posterior probability dist-    \n");
914     MrBayesPrint ("   ribution of trees analytically. Instead, the posterior probability            \n");
915     MrBayesPrint ("   of trees must be approximated. MrBayes uses a method called Markov chain      \n");
916     MrBayesPrint ("   Monte Carlo (MCMC) to approximate the posterior probability of trees.         \n");
917     MrBayesPrint ("   The object of MCMC is to construct a Markov chain that has as its state       \n");
918     MrBayesPrint ("   space the parameters of the phylogenetic model and a stationary distribution  \n");
919     MrBayesPrint ("   that is the posterior probability distribution of trees. MCMC takes valid,    \n");
920     MrBayesPrint ("   albeit dependent, samples from the posterior probability distribution of      \n");
921     MrBayesPrint ("   trees. The fraction of the time any tree appears in this sample is a          \n");
922     MrBayesPrint ("   valid approximation of the posterior probability of the tree. MrBayes keeps   \n");
923     MrBayesPrint ("   track of all the parameters of the phylogenetic model. The trees (with branch \n");
924     MrBayesPrint ("   lengths) that were sampled by the MCMC procedure are saved in one file        \n");
925     MrBayesPrint ("   (a file with a \".t\" extension) whereas the parameters of the model of       \n");
926     MrBayesPrint ("   character change are saved in another file (a file with a \".p\" ext-         \n");
927     MrBayesPrint ("   ension). You can summarize the results in the \".t\" and \".p\" files         \n");
928     MrBayesPrint ("   using the \"sumt\" and \"sump\" commands, respectively.                       \n");
929     MrBayesPrint ("                                                                                 \n");
930     MrBayesPrint ("   MrBayes was originally written by John Huelsenbeck in August of 2000 and was  \n");
931     MrBayesPrint ("   intended to be distributed to a small number of people. In March of 2001,     \n");
932     MrBayesPrint ("   Fredrik Ronquist started making contributions to the program. The contribu-   \n");
933     MrBayesPrint ("   tions were of such a significant nature that he was made a coauthor of the    \n");
934     MrBayesPrint ("   program. Version 3 of MrBayes was a fully joint effort, started in the summer \n");
935     MrBayesPrint ("   of 2002 when JPH visited Sweden on a grant from the Wenner-Gren Foundations.  \n");
936     MrBayesPrint ("   Several others have contributed to the MrBayes code since then, most notably  \n");
937     MrBayesPrint ("   Paul van der Mark and Maxim Teslenko, both postdocs/programmers in Fredrik's  \n");
938     MrBayesPrint ("   lab. A large number of users and students, too many to list here, have also   \n");
939     MrBayesPrint ("   contributed importantly to the project (type 'Acknowledgments' for a list of  \n");
940     MrBayesPrint ("   some of them).                                                                \n");
941     MrBayesPrint ("                                                                                 \n");
942     MrBayesPrint ("   Since 2003, MrBayes has been distributed from SourceForge. Bugs can be repor- \n");
943     MrBayesPrint ("   ted to the MrBayes site on SourceForge or by contacting Maxim Teslenko        \n");
944     MrBayesPrint ("   (maxim.teslenko@nrm.se) directly.                                             \n");
945     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
946
947     return (NO_ERROR);
948 }
949
950
951 int DoAcknowledgments (void)
952 {
953     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
954     MrBayesPrint ("   Acknowledgments                                                               \n");
955     MrBayesPrint ("                                                                                 \n");
956     MrBayesPrint ("   JPH and FR would like to thank Gautam Altekar, Andrea Betancourt, Jon         \n");
957     MrBayesPrint ("   Bollback, Barry Hall, Jimmy McGuire, Rasmus Nielsen, David Swofford,          \n");
958     MrBayesPrint ("   Johan Nylander, Mikael Thollesson, and Derrick Zwickl for help during the     \n");
959     MrBayesPrint ("   initial development of this program. Gautam Altekar, especially, was instru-  \n");
960     MrBayesPrint ("   mental in getting the parallel version of the program working. Important bug- \n");
961     MrBayesPrint ("   fixes and additional functionality was contributed by Clemens Lakner, Sebas-  \n");
962     MrBayesPrint ("   tian Hoehna, Paul Lewis, Mark Holder, Julian Catchen and Bret Larget. Marc    \n");
963     MrBayesPrint ("   Suchard, Daniel Ayres and Aaron Darling got mrbayes working with beagle and   \n");
964     MrBayesPrint ("   contributed a lot of related functionality and bug fixes. Aaron Darling was   \n");
965     MrBayesPrint ("   instrumental in getting the Windows installer set up. Liu Liang and Dennis    \n");
966     MrBayesPrint ("   Pearl helped integrate MrBayes with BEST.                                     \n");
967     MrBayesPrint ("                                                                                 \n");
968     MrBayesPrint ("   Bug fixes and user support was provided by Paul van der Mark (2005-2007) and  \n");
969     MrBayesPrint ("   from 2010 by Maxim Teslenko (maxim.teslenko@nrm.se).                          \n");
970     MrBayesPrint ("                                                                                 \n");
971     MrBayesPrint ("   Our wives -- Edna Huelsenbeck and Eva Ronquist -- showed extraordinary        \n");
972     MrBayesPrint ("   patience with us while we spent many late nights programming.                 \n");
973     MrBayesPrint ("                                                                                 \n");
974     MrBayesPrint ("   JPH was supported by NSF grants DEB-007540 and MCB-0075404 and a Wenner-      \n");
975     MrBayesPrint ("   Gren scholarship while writing this program. FR was supported by grants       \n");
976     MrBayesPrint ("   from the Swedish Natural Science Research Council and the Swedish Research    \n");
977     MrBayesPrint ("   Council.                                                                      \n");
978     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
979
980     return (NO_ERROR);
981 }
982
983
984 int DoBeginParm (char *parmName, char *tkn)
985 {
986     if (expecting == Expecting(PARAMETER))
987         {
988         /* set Data (inDataBlock) *************************************************************/
989         if (!strcmp(parmName, "Data"))
990             {
991             if (FreeModel () == ERROR)
992                 return (ERROR);
993             if (FreeMatrix () == ERROR)
994                 return (ERROR);
995             MrBayesPrint ("   Reading data block\n");
996             inDataBlock = YES;
997             expecting = Expecting(SEMICOLON);
998             strcpy (spacer, "   ");
999             }
1000         /* set Characters (inCharactersBlock) *************************************************************/
1001         else if (!strcmp(parmName, "Characters"))
1002             {
1003             if (FreeModel () == ERROR)
1004                 return (ERROR);
1005             if (FreeCharacters () == ERROR)
1006                 return (ERROR);
1007             MrBayesPrint ("   Reading characters block\n");
1008             inCharactersBlock = YES;
1009             expecting = Expecting(SEMICOLON);
1010             strcpy (spacer, "   ");
1011             }
1012         /* set Taxa (inTaxaBlock) *************************************************************/
1013         else if (!strcmp(parmName, "Taxa"))
1014             {
1015             if (FreeModel () == ERROR)
1016                 return (ERROR);
1017             if (FreeMatrix () == ERROR)
1018                 return (ERROR);
1019             MrBayesPrint ("   Reading taxa block\n");
1020             inTaxaBlock = YES;
1021             expecting = Expecting(SEMICOLON);
1022             strcpy (spacer, "   ");
1023             }
1024         /* set Mrbayes (inMrbayesBlock) *******************************************************/
1025         else if (!strcmp(parmName, "Mrbayes"))
1026             {
1027             MrBayesPrint ("   Reading mrbayes block\n");
1028             inMrbayesBlock = YES;
1029             expecting = Expecting(SEMICOLON);
1030             strcpy (spacer, "   ");
1031             }
1032         /* set Trees (inTreesBlock) *******************************************************/
1033         else if (!strcmp(parmName, "Trees"))
1034             {
1035             MrBayesPrint ("   Reading trees block\n");
1036             inTreesBlock = YES;
1037             expecting = Expecting(SEMICOLON);
1038             strcpy (spacer, "   ");
1039             }
1040         /* set Foreign (inForeignBlock) *******************************************************/
1041         else
1042             {
1043             MrBayesPrint ("   Skipping \"%s\" block\n", tkn);
1044             inForeignBlock = YES;
1045             expecting = Expecting(SEMICOLON);
1046             strcpy (spacer, "");
1047             }
1048         }
1049     else
1050         return (ERROR);
1051
1052     return (NO_ERROR);
1053 }
1054
1055
1056 int DoBreaks (void)
1057 {
1058     int         i, numBreaks;
1059     
1060     numBreaks = 0;
1061     for (i=0; i<numChar; i++)
1062         {
1063         if (charInfo[i].bigBreakAfter == YES)
1064             {
1065             numBreaks++;
1066             }
1067         }
1068         
1069     if (numBreaks > 0)
1070         {
1071         if (numBreaks == 1)
1072             MrBayesPrint ("%s   One data break found after character ", spacer, numBreaks);
1073         else
1074             MrBayesPrint ("%s   %d data breaks found after characters: ", spacer, numBreaks);
1075         for (i=0; i<numChar; i++)
1076             {
1077             if (charInfo[i].bigBreakAfter == YES)
1078                 {
1079                 MrBayesPrint ("%d ", i+1);
1080                 }
1081             }
1082         MrBayesPrint ("\n");
1083
1084         if (numBreaks == 1)
1085             MrBayesPrint ("%s   Successfully defined one break in data\n", spacer);
1086         else
1087             MrBayesPrint ("%s   Successfully defined %d breaks in data\n", spacer, numBreaks);
1088         }
1089     else
1090         {
1091         MrBayesPrint ("%s   No breaks in data found\n", spacer);
1092         }
1093         
1094     return (NO_ERROR);
1095 }
1096
1097
1098 int DoBreaksParm (char *parmName, char *tkn)
1099 {
1100     int     i, tempInt;
1101         
1102     if (defMatrix == NO)
1103         {
1104         MrBayesPrint ("%s   A matrix must be specified before you can define breaks in the data\n", spacer);
1105         return (ERROR);
1106         }
1107             
1108     if (expecting == Expecting(NUMBER))
1109         {
1110         sscanf (tkn, "%d", &tempInt);
1111         if (tempInt <= 0 || tempInt > numChar)
1112             {
1113             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
1114             for (i=0; i<numChar; i++)
1115                 charInfo[i].bigBreakAfter = NO;
1116             return (ERROR);
1117             }
1118         if (tempInt == numChar)
1119             {
1120             MrBayesPrint ("%s   Character number %d is the last character. MrBayes will define the\n", spacer, tempInt);
1121             MrBayesPrint ("%s   break, even though it doesn't make too much sense.\n", spacer);
1122             }
1123         tempInt--;
1124                     
1125         charInfo[tempInt].bigBreakAfter = YES;
1126         
1127         expecting  = (Expecting(NUMBER) | Expecting(SEMICOLON));
1128         }
1129     else
1130         {
1131         for (i=0; i<numChar; i++)
1132             charInfo[i].bigBreakAfter = NO;
1133         return (ERROR);
1134         }
1135
1136     return (NO_ERROR);
1137     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
1138 }
1139
1140
1141 int DoCalibrate (void)
1142 {
1143     int         i;
1144
1145     /* show calibration times (for debugging) */
1146 #   if 0
1147     MrBayesPrint ("Taxon ages\n");
1148     for (i=0; i<numTaxa; i++)
1149         MrBayesPrint ("%4d  --  %s\n", i+1, tipCalibration[i].name);
1150     MrBayesPrint ("Constraint ages\n");
1151     for (i=0; i<numDefinedConstraints; i++)
1152         {
1153         if (definedConstraintsType[i] != HARD)
1154             continue;
1155         MrBayesPrint ("%4d  --  %s\n", i+1, nodeCalibration[i].name);
1156         }
1157 #   endif
1158
1159     /* Update model if calibrations enforced */
1160     for (i=0; i<numCurrentDivisions; i++)
1161         {
1162         if (!strcmp(modelParams[i].nodeAgePr,"Calibrated"))
1163             {
1164             if (SetUpAnalysis (&globalSeed) == ERROR)
1165                 return (ERROR);
1166             break;
1167             }
1168         }
1169
1170     return (NO_ERROR);
1171 }
1172
1173
1174 int DoCalibrateParm (char *parmName, char *tkn)
1175 {
1176     static int              isTaxon, paramIndex;
1177     static char             nodeName[100], calName[100];
1178     static MrBFlt           priorParams[3];
1179     static enum CALPRIOR    calPrior;
1180     int                     howMany, index;
1181     char                    s[20], tempStr[100];
1182     MrBFlt                  tempD;
1183         
1184     if (defMatrix == NO)
1185         {
1186         MrBayesPrint ("%s   A matrix must be specified before you can calibrate nodes\n", spacer);
1187         return (ERROR);
1188         }
1189         
1190     if (expecting == Expecting(PARAMETER))
1191         {
1192         if (strcmp(parmName, "Xxxxxxxxxx") != 0)
1193             {
1194             MrBayesPrint ("%s   Unexpected error - Wrong parmName in DoCalibrateParm\n", spacer);
1195             return (ERROR);
1196             }
1197
1198         /* find taxon with this name */
1199         calibrationPtr = NULL;
1200         howMany = 0;
1201
1202         /* first look in constraint names */
1203         if (CheckString (constraintNames, numDefinedConstraints, tkn, &index) != ERROR && definedConstraintsType[index] == HARD)
1204             {
1205             calibrationPtr = &nodeCalibration[index];
1206             howMany++;
1207             isTaxon = NO;
1208             strcpy (nodeName, tkn);
1209             }
1210         
1211         /* then look in terminal taxon names */
1212         if (CheckString (taxaNames, numTaxa, tkn, &index) != ERROR)
1213             {
1214             calibrationPtr = &tipCalibration[index];
1215             howMany++;
1216             isTaxon = YES;
1217             strcpy (nodeName, tkn);
1218             }
1219
1220         /* return error if not found or ambiguous */
1221         if (howMany == 0)
1222             {
1223             MrBayesPrint ("%s   No taxon or hard constraint named ""%s"" found. Note that only hard constraint can be calibrated.\n", spacer, tkn);
1224             return (ERROR);
1225             }
1226         else if (howMany > 1)
1227             {
1228             MrBayesPrint ("%s   Both a taxon and a constraint named ""%s"" encountered -- please rename one\n", spacer, tkn);
1229             return (ERROR);
1230             }
1231
1232         /* get ready to find the equal sign */
1233         expecting = Expecting(EQUALSIGN);
1234         }
1235
1236     else if (expecting == Expecting(EQUALSIGN))
1237         {
1238         /* get ready to find the calibration prior */
1239         expecting = Expecting(ALPHA);
1240         }
1241
1242     else if (expecting == Expecting(ALPHA))
1243         {
1244         /* set the calibration prior type */
1245         if (IsArgValid(tkn,tempStr) == NO_ERROR)
1246             {
1247             if (!strcmp (tempStr, "Unconstrained"))
1248                 calPrior = unconstrained;
1249             else if (!strcmp (tempStr, "Fixed"))
1250                 calPrior = fixed;
1251             else if (!strcmp (tempStr, "Uniform"))
1252                 calPrior = uniform;
1253             else if (!strcmp (tempStr, "Offsetexponential"))
1254                 calPrior = offsetExponential;
1255             else if (!strcmp (tempStr, "Truncatednormal"))
1256                 calPrior = truncatedNormal;
1257             else if (!strcmp (tempStr, "Lognormal"))
1258                 calPrior = logNormal;
1259             else if (!strcmp (tempStr, "Offsetlognormal"))
1260                 calPrior = offsetLogNormal;
1261             else if (!strcmp (tempStr, "Gamma"))
1262                 calPrior = standardGamma;
1263             else if (!strcmp (tempStr, "Offsetgamma"))
1264                 calPrior = offsetGamma;
1265
1266             if (calPrior == unconstrained)
1267                 {
1268                 /* reset the values of the calibration */
1269                 MrBayesPrint ("%s   Resetting previous calibration for ""%s""\n", spacer, nodeName);
1270
1271                 calibrationPtr->prior           = defaultCalibration.prior;
1272                 calibrationPtr->priorParams[0]  = defaultCalibration.priorParams[0];
1273                 calibrationPtr->priorParams[1]  = defaultCalibration.priorParams[1];
1274                 calibrationPtr->priorParams[2]  = defaultCalibration.priorParams[2];
1275                 calibrationPtr->LnPriorProb     = defaultCalibration.LnPriorProb;
1276                 calibrationPtr->LnPriorRatio    = defaultCalibration.LnPriorRatio;
1277                 calibrationPtr->min             = defaultCalibration.min;
1278                 calibrationPtr->max             = defaultCalibration.max;
1279                 strcpy(calibrationPtr->name, defaultCalibration.name);
1280             
1281                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
1282                 }
1283             else
1284                 {
1285                 strcpy (calName, tempStr);
1286                 paramIndex = 0;
1287                 priorParams[0] = priorParams[1] = priorParams[2] =  -1.0;
1288                 expecting = Expecting(LEFTPAR);
1289                 }
1290             }
1291         else
1292             {
1293             MrBayesPrint ("%s   Invalid calibration prior argument \n", spacer);
1294             return (ERROR);
1295             }
1296         }
1297     else if (expecting == Expecting(LEFTPAR))
1298         {
1299         strcat (calName, "(");
1300         expecting  = Expecting(NUMBER);
1301         }
1302     else if (expecting == Expecting(NUMBER))
1303         {
1304         sscanf (tkn, "%lf", &tempD);
1305         if (paramIndex == 0)
1306             {
1307             if (calPrior == logNormal)
1308                 {
1309                 if (tempD < 0.0)
1310                     {
1311                     MrBayesPrint ("%s   Mean age must be nonnegative\n", spacer);
1312                     MrBayesPrint ("%s   Parameters of the lognormal distribution used for dating are mean age\n", spacer);
1313                     MrBayesPrint ("%s   and standard deviation, both specified on the linear scale, not as log values.\n", spacer);
1314                     return (ERROR);
1315                     }
1316                 }
1317             else if (calPrior == standardGamma)
1318                 {
1319                 if (tempD <= 0.0)
1320                     {
1321                     MrBayesPrint ("%s   Mean parameter must be positive\n", spacer);
1322                     MrBayesPrint ("%s   Parameters of the gamma distribution used for dating are mean age and\n", spacer);
1323                     MrBayesPrint ("%s   standard deviation. In terms of the common shape (alpha) and rate (beta)\n", spacer);
1324                     MrBayesPrint ("%s   parameterization, the expected mean is alpha/beta and the standard\n", spacer);
1325                     MrBayesPrint ("%s   deviation is the square root of (alpha / beta^2).\n", spacer);
1326                     return (ERROR);
1327                     }
1328                 }
1329             else if (tempD < 0.0)
1330                 {
1331                 if (calPrior == fixed)
1332                     MrBayesPrint ("%s   Fixed age must be nonnegative\n", spacer);
1333                 else if (calPrior == uniform)
1334                     {
1335                     MrBayesPrint ("%s   Minimum age must be nonnegative\n", spacer);
1336                     MrBayesPrint ("%s   Parameters of the uniform are minimum age and maximum age.\n", spacer);
1337                     }
1338                 else if (calPrior == truncatedNormal)
1339                     {
1340                     MrBayesPrint ("%s   Offset (minimum or truncation) age must be nonnegative.\n", spacer);
1341                     MrBayesPrint ("%s   Parameters of the truncated normal distribution are offset (minimum\n", spacer);
1342                     MrBayesPrint ("%s   or truncation) age, mean age and standard deviation.\n", spacer);
1343                     }
1344                 else if (calPrior == offsetGamma)
1345                     {
1346                     MrBayesPrint ("%s   Offset age must be nonnegative\n", spacer);
1347                     MrBayesPrint ("%s   Parameters of the offset gamma distribution used for dating are offset age,\n", spacer);
1348                     MrBayesPrint ("%s   mean age, and standard deviation. In terms of the common shape (alpha) and\n", spacer);
1349                     MrBayesPrint ("%s   rate (beta) parameterization, the expected mean is alpha/beta and the standard\n", spacer);
1350                     MrBayesPrint ("%s   deviation is the square root of (alpha / beta^2).\n", spacer);
1351                     }
1352                 else if (calPrior == offsetExponential)
1353                     {
1354                     MrBayesPrint ("%s   Offset age must be nonnegative\n", spacer);
1355                     MrBayesPrint ("%s   Parameters of the offset exponential are offset age and mean age.\n", spacer);
1356                     }
1357                 else if (calPrior == offsetLogNormal)
1358                     {
1359                     MrBayesPrint ("%s   Offset age must be nonnegative\n", spacer);
1360                     MrBayesPrint ("%s   Parameters of the offset lognormal distribution are offset age, mean age,\n", spacer);
1361                     MrBayesPrint ("%s   and standard deviation. All values are specified on the linear scale, not\n", spacer);
1362                     MrBayesPrint ("%s   as log values.\n", spacer);
1363                     }
1364                 return (ERROR);
1365                 }
1366             priorParams[0] = tempD;
1367             if (calPrior == fixed)
1368                 expecting = Expecting(RIGHTPAR);
1369             else
1370                 expecting = Expecting(COMMA);
1371             }
1372         else if (paramIndex == 1)
1373             {
1374             if (calPrior == uniform)
1375                 {
1376                 if (tempD <= priorParams[0])
1377                     {
1378                     MrBayesPrint ("%s   Maximum age of uniform distribution must be larger than minimum age\n", spacer);
1379                     return (ERROR);
1380                     }
1381                 }
1382             else if (calPrior == offsetExponential)
1383                 {
1384                 if (tempD <= priorParams[0])
1385                     {
1386                     MrBayesPrint ("%s   Mean age must be larger than offset age.\n", spacer);
1387                     MrBayesPrint ("%s   MrBayes now uses offset and mean rather than offset and rate\n", spacer);
1388                     MrBayesPrint ("%s   as the parameters for the offset exponential distribution.\n", spacer);
1389                     return (ERROR);
1390                     }
1391                 }
1392             else if (calPrior == truncatedNormal)
1393                 {
1394                 if (tempD <= priorParams[0])
1395                     {
1396                     MrBayesPrint ("%s   Mean age must be larger than offset (truncation) age.\n", spacer);
1397                     MrBayesPrint ("%s   Parameters of the truncated normal distribution are offset (minimum\n", spacer);
1398                     MrBayesPrint ("%s   or truncation) age, mean age and standard deviation\n", spacer);
1399                     return (ERROR);
1400                     }
1401                 }
1402             else if (calPrior == logNormal)
1403                 {
1404                 if (tempD <= 0.0)
1405                     {
1406                     MrBayesPrint ("%s   Standard deviation must be positive.\n", spacer);
1407                     MrBayesPrint ("%s   Parameters of the lognormal distribution used for dating are mean age\n", spacer);
1408                     MrBayesPrint ("%s   and standard deviation, both specified on the linear scale, not as log values.\n", spacer);
1409                     return (ERROR);
1410                     }
1411                 }
1412             else if (calPrior == offsetLogNormal)
1413                 {
1414                 if (tempD <= priorParams[0])
1415                     {
1416                     MrBayesPrint ("%s   Mean age must be larger than offset age.\n", spacer);
1417                     MrBayesPrint ("%s   Parameters of the offset lognormal distribution are offset age, mean age,\n", spacer);
1418                     MrBayesPrint ("%s   and standard deviation. All values are specified on the linear scale, not\n", spacer);
1419                     MrBayesPrint ("%s   as log values.\n", spacer);
1420                     return (ERROR);
1421                     }
1422                 }
1423             else if (calPrior == standardGamma)
1424                 {
1425                 if (tempD <= 0.0)
1426                     {
1427                     MrBayesPrint ("%s   Standard deviation must be positive.\n", spacer);
1428                     MrBayesPrint ("%s   Parameters of the gamma distribution used for dating are mean age and\n", spacer);
1429                     MrBayesPrint ("%s   standard deviation. In terms of the common shape (alpha) and rate (beta)\n", spacer);
1430                     MrBayesPrint ("%s   parameterization, the expected mean is alpha/beta and the standard\n", spacer);
1431                     MrBayesPrint ("%s   deviation is the square root of (alpha / beta^2).\n", spacer);
1432                     return (ERROR);
1433                     }
1434                 }
1435             else if (calPrior == offsetGamma)
1436                 {
1437                 if (tempD <= 0.0)
1438                     {
1439                     MrBayesPrint ("%s   Mean age must be positive.\n", spacer);
1440                     MrBayesPrint ("%s   Parameters of the offset gamma distribution used for dating are offset age,\n", spacer);
1441                     MrBayesPrint ("%s   mean age, and standard deviation. In terms of the common shape (alpha) and\n", spacer);
1442                     MrBayesPrint ("%s   rate (beta) parameterization, the expected mean is alpha/beta and the standard\n", spacer);
1443                     MrBayesPrint ("%s   deviation is the square root of (alpha / beta^2).\n", spacer);
1444                     return (ERROR);
1445                     }
1446                 }
1447
1448             priorParams[1] = tempD;
1449             if (calPrior == uniform || calPrior == standardGamma || calPrior == logNormal || calPrior == offsetExponential)
1450                 expecting = Expecting(RIGHTPAR);
1451             else
1452                 expecting = Expecting(COMMA);
1453             }
1454         else /* if (paramIndex == 2) */
1455             {
1456             if (calPrior == offsetGamma)
1457                 {
1458                 if (tempD <= 0.0)
1459                     {
1460                     MrBayesPrint ("%s   Standard deviation must be positive.\n", spacer);
1461                     MrBayesPrint ("%s   Parameters of the offset gamma distribution used for dating are offset age,\n", spacer);
1462                     MrBayesPrint ("%s   mean age, and standard deviation. In terms of the common shape (alpha) and\n", spacer);
1463                     MrBayesPrint ("%s   rate (beta) parameterization, the expected mean is alpha/beta and the standard\n", spacer);
1464                     MrBayesPrint ("%s   deviation is the square root of (alpha / beta^2).\n", spacer);
1465                     return (ERROR);
1466                     }
1467                 }
1468             else if (calPrior == offsetLogNormal)
1469                 {
1470                 if (tempD <= 0.0)
1471                     {
1472                     MrBayesPrint ("%s   Standard deviation must be positive.\n", spacer);
1473                     MrBayesPrint ("%s   Parameters of the offset lognormal distribution are offset age, mean age,\n", spacer);
1474                     MrBayesPrint ("%s   and standard deviation. All values are specified on the linear scale, not\n", spacer);
1475                     MrBayesPrint ("%s   as log values.\n", spacer);
1476                     return (ERROR);
1477                     }
1478                 }
1479             priorParams[2] = tempD;
1480             expecting = Expecting(RIGHTPAR);
1481             }
1482         sprintf (s, "%1.2lf", tempD);
1483         strcat (calName, s);
1484         }
1485     else if (expecting == Expecting(COMMA))
1486         {
1487         strcat (calName, ",");
1488         paramIndex++;
1489         expecting  = Expecting(NUMBER);
1490         }
1491     else if (expecting == Expecting(RIGHTPAR))
1492         {
1493         strcat (calName, ")");
1494         if (isTaxon == YES)
1495             MrBayesPrint ("%s   Setting age of taxon '%s' to %s\n", spacer, nodeName, calName);
1496         else
1497             MrBayesPrint ("%s   Setting age of constraint node '%s' to %s\n", spacer, nodeName, calName);
1498
1499         /* set calibration based on collected values and settings */
1500         strcpy(calibrationPtr->name, calName);
1501         calibrationPtr->priorParams[0]  = priorParams[0];
1502         calibrationPtr->priorParams[1]  = priorParams[1];
1503         calibrationPtr->priorParams[2]  = priorParams[2];
1504         calibrationPtr->prior           = calPrior;
1505         if (calPrior == fixed)
1506             {
1507             calibrationPtr->LnPriorProb     = &LnPriorProbFix;
1508             calibrationPtr->LnPriorRatio    = &LnProbRatioFix;
1509             calibrationPtr->min             = priorParams[0];
1510             calibrationPtr->max             = priorParams[0];
1511             }
1512         else if (calPrior == uniform)
1513             {
1514             calibrationPtr->LnPriorProb     = &LnPriorProbUniform;
1515             calibrationPtr->LnPriorRatio    = &LnProbRatioUniform;
1516             calibrationPtr->min             = priorParams[0];
1517             calibrationPtr->max             = priorParams[1];
1518             }
1519         else if (calPrior == offsetExponential)
1520             {
1521             calibrationPtr->LnPriorProb     = &LnPriorProbOffsetExponential_Param_Offset_Mean;
1522             calibrationPtr->LnPriorRatio    = &LnProbRatioOffsetExponential_Param_Offset_Mean;
1523             calibrationPtr->min             = priorParams[0];
1524             calibrationPtr->max             = POS_INFINITY;
1525             }
1526         else if (calPrior == truncatedNormal)
1527             {
1528             calibrationPtr->LnPriorProb     = &LnPriorProbTruncatedNormal_Param_Trunc_Mean_Sd;
1529             calibrationPtr->LnPriorRatio    = &LnProbRatioTruncatedNormal_Param_Trunc_Mean_Sd;
1530             calibrationPtr->min             = priorParams[0];
1531             calibrationPtr->max             = POS_INFINITY;
1532             }
1533         else if (calPrior == logNormal)
1534             {
1535             calibrationPtr->LnPriorProb     = &LnPriorProbLognormal_Param_Mean_Sd;
1536             calibrationPtr->LnPriorRatio    = &LnProbRatioLognormal_Param_Mean_Sd;
1537             calibrationPtr->min             = BRLENS_MIN;
1538             calibrationPtr->max             = POS_INFINITY;
1539             }
1540         else if (calPrior == offsetLogNormal)
1541             {
1542             calibrationPtr->LnPriorProb     = &LnPriorProbOffsetLognormal_Param_Offset_Mean_Sd;
1543             calibrationPtr->LnPriorRatio    = &LnProbRatioOffsetLognormal_Param_Offset_Mean_Sd;
1544             calibrationPtr->min             = BRLENS_MIN + priorParams[0];
1545             calibrationPtr->max             = POS_INFINITY;
1546             }
1547         else if (calPrior == standardGamma)
1548             {
1549             calibrationPtr->LnPriorProb     = &LnPriorProbGamma_Param_Mean_Sd;
1550             calibrationPtr->LnPriorRatio    = &LnProbRatioGamma_Param_Mean_Sd;
1551             calibrationPtr->min             = BRLENS_MIN;
1552             calibrationPtr->max             = POS_INFINITY;
1553             }
1554         else if (calPrior == offsetGamma)
1555             {
1556             calibrationPtr->LnPriorProb     = &LnPriorProbOffsetGamma_Param_Offset_Mean_Sd;
1557             calibrationPtr->LnPriorRatio    = &LnProbRatioOffsetGamma_Param_Offset_Mean_Sd;
1558             calibrationPtr->min             = BRLENS_MIN + priorParams[0];
1559             calibrationPtr->max             = POS_INFINITY;
1560             }
1561
1562         /* get ready to find more calibrated nodes or taxa, if present */
1563         expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
1564         }
1565     else
1566         return (ERROR);
1567
1568     return (NO_ERROR);
1569 }
1570
1571
1572 int DoCharset (void)
1573 {
1574     /* first add set to tempSet */
1575     if (fromI >= 0 && toJ < 0)
1576         {
1577         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1578             return (ERROR);
1579         }
1580     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
1581         {
1582         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1583             return (ERROR);
1584         }
1585     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
1586         {
1587         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1588             return (ERROR);
1589         }
1590         
1591     /* add name to charSetNames */
1592     if (AddString (&charSetNames, numCharSets, tempSetName) == ERROR)
1593         {
1594         MrBayesPrint ("%s   Problem adding charset %s to list\n", spacer, tempSetName);
1595         return (ERROR);
1596         }
1597
1598     /* store charset */
1599     AddBitfield (&charSet, numCharSets, tempSet, numChar);
1600
1601     /* increment number of char sets */
1602     numCharSets++;
1603
1604     return (NO_ERROR);
1605 }
1606
1607
1608 int DoCharsetParm (char *parmName, char *tkn)
1609 {
1610     int     i, index, tempInt, allDigit;
1611     
1612     if (defMatrix == NO)
1613         {
1614         MrBayesPrint ("%s   A matrix must be specified before charsets can be defined\n", spacer);
1615         return (ERROR);
1616         }
1617
1618     if (expecting == Expecting(PARAMETER))
1619         {
1620         if (!strcmp(parmName, "Xxxxxxxxxx"))
1621             {
1622             /* check that the name of the charset is not a number */
1623             allDigit = YES;
1624             for (i=0; i<(int)strlen(tkn); i++)
1625                 {
1626                 if (tkn[i] == '0' || tkn[i] == '1' || tkn[i] == '2' || tkn[i] == '3' || tkn[i] == '4' || 
1627                     tkn[i] == '5' || tkn[i] == '6' || tkn[i] == '7' || tkn[i] == '8' || tkn[i] == '9' || tkn[i] == '.')
1628                     {}
1629                 else
1630                     allDigit = NO;
1631                 }
1632             if (allDigit == YES)
1633                 {
1634                 MrBayesPrint ("%s   Charset name may not be a number\n", spacer);
1635                 return (ERROR);
1636                 }
1637             
1638             /* check size of charset name */
1639             if (strlen(tkn) > 99)
1640                 {
1641                 MrBayesPrint ("%s   Charset name is too long\n", spacer);
1642                 return (ERROR);
1643                 }
1644                 
1645             /* check to see if the name has already been used as a charset */
1646             if (numCharSets > 1)
1647                 {
1648                 if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
1649                     {
1650                     /* if the charset name has not been used, then we should have an ERROR returned */
1651                     /* we _want_ to be here */
1652
1653                     }
1654                 else
1655                     {
1656                     MrBayesPrint ("%s   Charset name has been used previously\n", spacer);
1657                     return (ERROR);
1658                     }
1659                 }
1660                 
1661             /* add the name to the character set */
1662             strcpy (tempSetName, tkn);
1663             
1664             /* clear tempSet */
1665             for (i=0; i<numChar; i++)
1666                 tempSet[i] = 0;
1667             
1668             fromI = toJ = everyK = -1;
1669             foundDash = foundSlash = NO;
1670             MrBayesPrint ("%s   Defining charset called '%s'\n", spacer, tkn);
1671             expecting = Expecting(EQUALSIGN);
1672             }
1673         else
1674             return (ERROR);
1675         }
1676     else if (expecting == Expecting(EQUALSIGN))
1677         {
1678         expecting  = Expecting(ALPHA);
1679         expecting |= Expecting(NUMBER);
1680         }
1681     else if (expecting == Expecting(ALPHA))
1682         {
1683         /* We are defining a character set in terms of another (called tkn, here). We should be able
1684            to find tkn in the list of character set names. If we cannot, then we have a problem and
1685            return an error. */
1686         if (numCharSets < 1)
1687             {
1688             MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
1689             return (ERROR);
1690             }
1691         if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
1692             {
1693             MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
1694             return (ERROR);
1695             }
1696         /* add characters from charset "tkn" to new tempset */
1697         for (i=0; i<numChar; i++)
1698             {
1699             if (IsBitSet(i,charSet[index]) == YES)
1700                 tempSet[i] = 1;
1701             }       
1702         fromI = toJ = everyK = -1;
1703
1704         expecting  = Expecting(ALPHA);
1705         expecting |= Expecting(NUMBER);
1706         expecting |= Expecting(SEMICOLON);
1707         }
1708     else if (expecting == Expecting(NUMBER))
1709         {
1710         if (strlen(tkn) == 1 && tkn[0] == '.')
1711             tempInt = numChar;
1712         else
1713             sscanf (tkn, "%d", &tempInt);
1714         if (tempInt <= 0 || tempInt > numChar)
1715             {
1716             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
1717             return (ERROR);
1718             }
1719         tempInt--;
1720         if (foundDash == YES)
1721             {
1722             if (fromI >= 0)
1723                 toJ = tempInt;
1724             else
1725                 {
1726                 MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
1727                 return (ERROR);
1728                 }
1729             foundDash = NO;
1730             }
1731         else if (foundSlash == YES)
1732             {
1733             tempInt++;
1734             if (tempInt <= 1)
1735                 {
1736                 MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
1737                 return (ERROR);
1738                 }
1739             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
1740                 everyK = tempInt;
1741             else
1742                 {
1743                 MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
1744                 return (ERROR);
1745                 }
1746             foundSlash = NO;
1747             }
1748         else
1749             {
1750             if (fromI >= 0 && toJ < 0)
1751                 {
1752                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1753                     return (ERROR);
1754                 fromI = tempInt;
1755                 }
1756             else if (fromI < 0 && toJ < 0)
1757                 {
1758                 fromI = tempInt;
1759                 }
1760             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
1761                 {
1762                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1763                     return (ERROR);
1764                 fromI = tempInt;
1765                 toJ = everyK = -1;
1766                 }
1767             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
1768                 {
1769                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
1770                     return (ERROR);
1771                 fromI = tempInt;
1772                 toJ = everyK = -1;
1773                 }
1774             else
1775                 {
1776                 MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
1777                     {
1778                     return (ERROR);
1779                     }
1780                 }
1781                 
1782             }
1783
1784         
1785         expecting  = Expecting(ALPHA);
1786         expecting |= Expecting(NUMBER);
1787         expecting |= Expecting(SEMICOLON);
1788         expecting |= Expecting(DASH);
1789         expecting |= Expecting(BACKSLASH);
1790         }
1791     else if (expecting == Expecting(DASH))
1792         {
1793         foundDash = YES;
1794         expecting = Expecting(NUMBER);
1795         }
1796     else if (expecting == Expecting(BACKSLASH))
1797         {
1798         foundSlash = YES;
1799         expecting = Expecting(NUMBER);
1800         }
1801     else
1802         return (ERROR);
1803
1804     return (NO_ERROR);
1805 }
1806
1807
1808 int DoCharStat (void)
1809 {
1810     int         i, j, numDivs;
1811     char        tempName[100];
1812     
1813     if (defMatrix == NO)
1814         {
1815         MrBayesPrint ("%s   A character matrix must be defined first\n", spacer);
1816         return (ERROR);
1817         }
1818             
1819     if (numDefinedPartitions == 1)
1820         MrBayesPrint ("%s   1 character partition defined:\n", spacer, numDefinedPartitions);
1821     else
1822         MrBayesPrint ("%s   %d character partitions defined:\n", spacer, numDefinedPartitions);
1823     for (i=0; i<numDefinedPartitions; i++)
1824         {
1825         numDivs = GetNumPartDivisions (i);
1826         if (numDivs == 1)
1827             MrBayesPrint ("%s      Partition %d (\"%s\") does not divide the characters\n", spacer, i+1, partitionNames[i]);
1828         else
1829             MrBayesPrint ("%s      Partition %d (\"%s\") divides the characters into %d parts\n", spacer, i+1, partitionNames[i], numDivs);
1830         }
1831     MrBayesPrint ("%s      Current partition is \"%s\"\n", spacer, partitionNames[partitionNum]);
1832     MrBayesPrint ("\n");
1833
1834     /* print out list of characters with information about each */
1835     MrBayesPrint ("%s   Showing character status:\n\n", spacer);
1836     MrBayesPrint ("%s                                                    Partition(s)\n", spacer);
1837     MrBayesPrint ("%s      #      Type      In/Out    Ambiguity Order  ", spacer);
1838     for (i=0; i<numDefinedPartitions; i++)
1839         MrBayesPrint (" %2d", i+1);
1840     MrBayesPrint ("\n");
1841     MrBayesPrint ("%s   -----------------------------------------------", spacer);
1842     for (i=0; i<numDefinedPartitions; i++)
1843         MrBayesPrint ("---");
1844     MrBayesPrint ("\n");
1845     for (i=0; i<numChar; i++)
1846         {
1847         MrBayesPrint ("%s   %4d -- ", spacer, i+1);
1848                 
1849         if (charInfo[i].charType == DNA)
1850             MrBayesPrint ("   DNA");
1851         else if (charInfo[i].charType == RNA)
1852             MrBayesPrint ("   RNA");
1853         else if (charInfo[i].charType == PROTEIN)
1854             MrBayesPrint ("  Prot");
1855         else if (charInfo[i].charType == RESTRICTION)
1856             MrBayesPrint ("  Rest");
1857         else if (charInfo[i].charType == STANDARD)
1858             MrBayesPrint (" Stand");
1859         else if (charInfo[i].charType == CONTINUOUS)
1860             MrBayesPrint ("  Cont");
1861             
1862         if (charInfo[i].charType == DNA)
1863             MrBayesPrint ("   4");
1864         else if (charInfo[i].charType == RNA)
1865             MrBayesPrint ("   4");
1866         else if (charInfo[i].charType == PROTEIN)
1867             MrBayesPrint ("  20");
1868         else if (charInfo[i].charType == RESTRICTION)
1869             MrBayesPrint ("   2");
1870         else if (charInfo[i].charType == STANDARD)
1871             MrBayesPrint ("  %2d", charInfo[i].numStates);
1872         else if (charInfo[i].charType == CONTINUOUS)
1873             MrBayesPrint (" Inf");
1874             
1875         if (charInfo[i].isExcluded == NO)
1876             MrBayesPrint ("  Included");
1877         else
1878             MrBayesPrint ("  Excluded");
1879             
1880         if (charInfo[i].isMissAmbig == YES)
1881             MrBayesPrint ("  MissAmbig");
1882         else
1883             MrBayesPrint ("       None");
1884             
1885         if (charInfo[i].ctype == UNORD)
1886             MrBayesPrint (" Unord");
1887         else if (charInfo[i].ctype == ORD)
1888             MrBayesPrint ("   Ord");
1889         else if (charInfo[i].ctype == DOLLO)
1890             MrBayesPrint (" Dollo");
1891         else if (charInfo[i].ctype == IRREV)
1892             MrBayesPrint (" Irrev");
1893
1894         MrBayesPrint ("  ");
1895             
1896         for (j=0; j<numDefinedPartitions; j++)
1897             MrBayesPrint (" %2d", partitionId[i][j]);
1898
1899         /* MrBayesPrint ("%4d   ", charSet[i]);*/
1900         
1901         if (charInfo[i].pairsId > 0)
1902             {
1903             /* find paired character */
1904             for (j=0; j<numChar; j++)
1905                 {
1906                 if (i != j && charInfo[j].pairsId == charInfo[i].pairsId)
1907                     {
1908                     MrBayesPrint (" (coupled with %d)", j+1);
1909                     break;
1910                     }
1911                 }
1912             }
1913                     
1914         MrBayesPrint ("\n");
1915         
1916         if (charInfo[i].bigBreakAfter == YES)
1917             {
1918             MrBayesPrint ("%s   ", spacer);
1919             MrBayesPrint ("     - - - - - - - - - - - - - - - - - - - -  \n");
1920             }
1921         
1922         /* we may want to pause */
1923         if (autoClose == NO)
1924             {
1925             if ((i+1) % 100 == 0)
1926                 {
1927                 MrBayesPrint ("%s   Hit return key to continue  ", spacer);
1928                 fflush (stdin);
1929                 if (fgets (tempName, 100, stdin) == NULL)
1930                     {
1931                     printf ("Error in function: %s at line: %d in file: %s", __FUNCTION__, __LINE__, __FILE__);
1932                     }
1933                 }
1934             }
1935         }
1936
1937     return (NO_ERROR);
1938 }
1939
1940
1941 int DoCitations (void)
1942 {
1943     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
1944     MrBayesPrint ("   Citations                                                                     \n");
1945     MrBayesPrint ("                                                                                 \n");
1946     MrBayesPrint ("   If you publish results obtained using MrBayes you may want to cite the        \n");
1947     MrBayesPrint ("   program using one of these papers:                                            \n");
1948     MrBayesPrint ("                                                                                 \n");
1949     MrBayesPrint ("      Huelsenbeck, J. P. and F. Ronquist. 2001. MRBAYES: Bayesian                \n");
1950     MrBayesPrint ("         inference of phylogeny. Bioinformatics 17:754-755.                      \n");
1951     MrBayesPrint ("      Ronquist, F. and J. P. Huelsenbeck. 2003. MRBAYES 3: Bayesian phylogenetic \n");
1952     MrBayesPrint ("         inference under mixed models. Bioinformatics 19:1572-1574.              \n");
1953     MrBayesPrint ("      Ronquist, F. et al. 2012. MRBAYES 3.2: Efficient Bayesian phylogenetic     \n");
1954     MrBayesPrint ("         inference and model selection across a large model space. Systematic    \n");
1955     MrBayesPrint ("         Biology 61 (in press).                                                  \n");
1956     MrBayesPrint ("                                                                                 \n");
1957     MrBayesPrint ("   If you use the parallel abilities of the program, you may also want to cite   \n");
1958     MrBayesPrint ("                                                                                 \n");
1959     MrBayesPrint ("      Altekar, G., S. Dwarkadas, J. P. Huelsenbeck, and F. Ronquist. 2004.       \n");
1960     MrBayesPrint ("         Parallel Metropolis-coupled Markov chain Monte Carlo for Bayesian       \n");
1961     MrBayesPrint ("         phylogenetic inference. Bioinformatics 20:407-415.                      \n");
1962     MrBayesPrint ("                                                                                 \n");
1963     MrBayesPrint ("   If you use the BEAGLE library, the appropriate citation is                    \n");
1964     MrBayesPrint ("                                                                                 \n");
1965     MrBayesPrint ("      Ayres, D. L., A. Darling, D. J. Zwickl, P. Beerli, M. T. Holder, P. O.     \n");
1966     MrBayesPrint ("         J. P. Huelsenbeck, F. Ronquist, D. L. Swofford, M. P. Cummings, A.      \n");
1967     MrBayesPrint ("         Rambaut, and M. A. Suchard. 2012. BEAGLE: an application programming    \n");
1968     MrBayesPrint ("         interface for statistical phylogenetics. Syst. Biol. 61:170-173.        \n");
1969     MrBayesPrint ("                                                                                 \n");
1970     MrBayesPrint ("                                                                                 \n");
1971     MrBayesPrint ("   You should also cite other papers for different ideas that are implemented    \n");
1972     MrBayesPrint ("   in the program. For example, the program performs Bayesian inference of       \n");
1973     MrBayesPrint ("   phylogeny, an idea that was first proposed in the following papers:           \n");
1974     MrBayesPrint ("                                                                                 \n");
1975     MrBayesPrint ("      Larget, B., and D. Simon. 1999. Markov chain Monte Carlo                   \n");
1976     MrBayesPrint ("         algorithms for the Bayesian analysis of phylogenetic trees.             \n");
1977     MrBayesPrint ("         Mol. Biol. Evol. 16:750-759.                                            \n");
1978     MrBayesPrint ("                                                                                 \n");
1979     MrBayesPrint ("      Li, S. 1996. Phylogenetic tree construction using Markov chain             \n");
1980     MrBayesPrint ("         Monte carlo. Ph. D. dissertation, Ohio State University, Columbus.      \n");
1981     MrBayesPrint ("                                                                                 \n");
1982     MrBayesPrint ("      Mau, B. 1996. Bayesian phylogenetic inference via Markov chain             \n");
1983     MrBayesPrint ("         Monte carlo methods. Ph. D. dissertation, University of                 \n");
1984     MrBayesPrint ("         Wisconsin, Madison.                                                     \n");
1985     MrBayesPrint ("                                                                                 \n");
1986     MrBayesPrint ("      Mau, B., and M. Newton. 1997. Phylogenetic inference for binary            \n");
1987     MrBayesPrint ("         data on dendrograms using Markov chain Monte Carlo. Journal of          \n");
1988     MrBayesPrint ("         Computational and Graphical Statistics 6:122-131.                       \n");
1989     MrBayesPrint ("                                                                                 \n");
1990     MrBayesPrint ("      Mau, B., M. Newton, and B. Larget. 1999. Bayesian phylogenetic             \n");
1991     MrBayesPrint ("         inference via Markov chain Monte carlo methods. Biometrics. 55:1-12.    \n");
1992     MrBayesPrint ("                                                                                 \n");
1993     MrBayesPrint ("      Newton, M., B. Mau, and B. Larget. 1999. Markov chain Monte Carlo          \n");
1994     MrBayesPrint ("         for the Bayesian analysis of evolutionary trees from aligned            \n");
1995     MrBayesPrint ("         molecular sequences. In Statistics in molecular biology (F. Seillier-   \n");
1996     MrBayesPrint ("         Moseiwitch, T. P. Speed, and M. Waterman, eds.). Monograph Series       \n");
1997     MrBayesPrint ("         of the Institute of Mathematical Statistics.                            \n");
1998     MrBayesPrint ("                                                                                 \n");
1999     MrBayesPrint ("      Rannala, B., and Z. Yang. 1996. Probability distribution of                \n");
2000     MrBayesPrint ("         molecular evolutionary trees: a new method of phylogenetic              \n");
2001     MrBayesPrint ("         inference. J. Mol. Evol. 43:304-311.                                    \n");
2002     MrBayesPrint ("                                                                                 \n");
2003     MrBayesPrint ("      Yang, Z., and B. Rannala. 1997. Bayesian phylogenetic inference            \n");
2004     MrBayesPrint ("         using DNA sequences: a Markov chain Monte carlo method. Molecular       \n");
2005     MrBayesPrint ("         Biology and Evolution. 14:717-724.                                      \n");
2006     MrBayesPrint ("                                                                                 \n");
2007     MrBayesPrint ("                                                                                 \n");
2008     MrBayesPrint ("   MrBayes uses Markov chain Monte Carlo (MCMC) to approximate the posterior     \n");
2009     MrBayesPrint ("   probability of trees. MCMC was developed in the following papers:             \n");
2010     MrBayesPrint ("                                                                                 \n");
2011     MrBayesPrint ("      Metropolis, N., A. W. Rosenbluth, M. N. Rosenbluth, A. H. Teller,          \n");
2012     MrBayesPrint ("         and E. Teller. 1953. Equations of state calculations by fast            \n");
2013     MrBayesPrint ("         computing machines. J. Chem. Phys. 21:1087-1091.                        \n");
2014     MrBayesPrint ("                                                                                 \n");
2015     MrBayesPrint ("      Hastings, W. K. 1970. Monte Carlo sampling methods using Markov            \n");
2016     MrBayesPrint ("         chains and their applications. Biometrika 57:97-109.                    \n");
2017     MrBayesPrint ("                                                                                 \n");
2018     MrBayesPrint ("   In particular, MrBayes implements a variant of MCMC that was described by     \n");
2019     MrBayesPrint ("   Charles Geyer:                                                                \n");
2020     MrBayesPrint ("                                                                                 \n");
2021     MrBayesPrint ("      Geyer, C. J. 1991. Markov chain Monte Carlo maximum likelihood.            \n");
2022     MrBayesPrint ("         Pages 156-163 in Computing Science and Statistics: Proceed-             \n");
2023     MrBayesPrint ("         ings of the 23rd Symposium on the Interface. (E. M. Keramidas,          \n");
2024     MrBayesPrint ("         ed.). Fairfax Station: Interface Foundation.                            \n");
2025     MrBayesPrint ("                                                                                 \n");
2026     MrBayesPrint ("                                                                                 \n");
2027     MrBayesPrint ("   MrBayes implements a large number of DNA substitution models. These models    \n");
2028     MrBayesPrint ("   are of three different structures. The \"4by4\" models are the usual          \n");
2029     MrBayesPrint ("   flavor of phylogenetic models. The \"Doublet\" model was first proposed       \n");
2030     MrBayesPrint ("   by                                                                            \n");
2031     MrBayesPrint ("                                                                                 \n");
2032     MrBayesPrint ("      Schoniger, M., and A. von Haeseler. 1994. A stochastic model and the       \n");
2033     MrBayesPrint ("         evolution of autocorrelated DNA sequences. Molecular Phylogenetics      \n");
2034     MrBayesPrint ("         and Evolution 3:240-247.                                                \n");
2035     MrBayesPrint ("                                                                                 \n");
2036     MrBayesPrint ("   The program also implements codon models. Two papers, published back-to-back  \n");
2037     MrBayesPrint ("   were the first to implement a codon model of DNA substitution in which the    \n");
2038     MrBayesPrint ("   substitution process is modelled on the codon, not on a site-by-site basis:   \n");
2039     MrBayesPrint ("                                                                                 \n");
2040     MrBayesPrint ("      Goldman, N., and Z. Yang. 1994. A codon-based model of nucleotide          \n");
2041     MrBayesPrint ("         substitution for protein coding DNA sequences. Molecular Biology        \n");
2042     MrBayesPrint ("         and Evolution. 11:725-736.                                              \n");
2043     MrBayesPrint ("                                                                                 \n");
2044     MrBayesPrint ("      Muse, S., and B. Gaut. 1994. A likelihood approach for comparing           \n");
2045     MrBayesPrint ("         synonymous and non-synonymous substitution rates, with application      \n");
2046     MrBayesPrint ("         to the chloroplast genome. Molecular Biology and Evolution.             \n");
2047     MrBayesPrint ("         11:715-724.                                                             \n");
2048     MrBayesPrint ("                                                                                 \n");
2049     MrBayesPrint ("   The program can be used to detect positively slected amino-acid sites using   \n");
2050     MrBayesPrint ("   a full hierarchical Bayes analysis. The method is based on the excellent paper\n");
2051     MrBayesPrint ("   by Nielsen and Yang:                                                          \n");
2052     MrBayesPrint ("                                                                                 \n");
2053     MrBayesPrint ("      Nielsen, R., and Z. Yang. 1998. Likelihood models for detecting            \n");
2054     MrBayesPrint ("         positively selected amino acid sites and applications to the HIV-1      \n");
2055     MrBayesPrint ("         envelope gene. Genetics. 148:929-936.                                   \n");
2056     MrBayesPrint ("                                                                                 \n");
2057     MrBayesPrint ("   The previous four papers describe three different stuctures for the nuc-      \n");
2058     MrBayesPrint ("   leotide models implemented in MrBayes--the four-by-four models, the           \n");
2059     MrBayesPrint ("   16-by-16 (doublet) models and the 64-by-64 (codon) models. The program        \n");
2060     MrBayesPrint ("   implements three different substitution models within each model structure.   \n");
2061     MrBayesPrint ("   These include the nst=1 models:                                               \n");
2062     MrBayesPrint ("                                                                                 \n");
2063     MrBayesPrint ("      Jukes, T., and C. Cantor. 1969. Evolution of protein molecules.            \n");
2064     MrBayesPrint ("         Pages 21-132 in Mammalian Protein Metabolism. (H. Munro, ed.).          \n");
2065     MrBayesPrint ("         Academic Press, New York.                                               \n");
2066     MrBayesPrint ("                                                                                 \n");
2067     MrBayesPrint ("      Felsenstein, J. 1981. Evolutionary trees from DNA sequences: A             \n");
2068     MrBayesPrint ("         maximum likelihood approach. Journal of Molecular Evolution             \n");
2069     MrBayesPrint ("         17:368-376.                                                             \n");
2070     MrBayesPrint ("                                                                                 \n");
2071     MrBayesPrint ("   the nst=2 models:                                                             \n");
2072     MrBayesPrint ("                                                                                 \n");
2073     MrBayesPrint ("      Kimura, M. 1980. A simple method for estimating evolutionary rates         \n");
2074     MrBayesPrint ("         of base substitutions through comparative studies of nucleotide         \n");
2075     MrBayesPrint ("         sequences. Journal of Molecular Evolution. 16:111-120.                  \n");
2076     MrBayesPrint ("                                                                                 \n");
2077     MrBayesPrint ("      Hasegawa, M., T. Yano, and H. Kishino. 1984. A new molecular clock         \n");
2078     MrBayesPrint ("         of mitochondrial DNA and the evolution of Hominoids. Proc.              \n");
2079     MrBayesPrint ("         Japan Acad. Ser. B 60:95-98.                                            \n");
2080     MrBayesPrint ("                                                                                 \n");
2081     MrBayesPrint ("      Hasegawa, M., H. Kishino, and T. Yano. 1985. Dating the human-ape          \n");
2082     MrBayesPrint ("         split by a molecular clock of mitochondrial DNA. Journal of             \n");
2083     MrBayesPrint ("         Molecular Evolution 22:160-174.                                         \n");
2084     MrBayesPrint ("                                                                                 \n");
2085     MrBayesPrint ("   and the the nst=6 models:                                                     \n");
2086     MrBayesPrint ("                                                                                 \n");
2087     MrBayesPrint ("      Tavare, S. 1986. Some probabilistic and statisical problems on the         \n");
2088     MrBayesPrint ("         analysis of DNA sequences. Lect. Math. Life Sci. 17:57-86.              \n");
2089     MrBayesPrint ("         17:368-376.                                                             \n");
2090     MrBayesPrint ("                                                                                 \n");
2091     MrBayesPrint ("                                                                                 \n");
2092     MrBayesPrint ("   MrBayes implements a large number of amino-acid models. These include:        \n");
2093     MrBayesPrint ("                                                                                 \n");
2094     MrBayesPrint ("      Poisson --                                                                 \n");
2095     MrBayesPrint ("                                                                                 \n");
2096     MrBayesPrint ("      Bishop, M.J., and A.E. Friday. 1987. Tetropad relationships: the           \n");
2097     MrBayesPrint ("         molecular evidence. Pp. 123-139 in Molecules and morphology in          \n");
2098     MrBayesPrint ("         evolution: conflict or compromise? (C. Patterson, ed.). Cambridge       \n");
2099     MrBayesPrint ("         University Press, Cambridge, England.                                   \n");
2100     MrBayesPrint ("                                                                                 \n");
2101     MrBayesPrint ("      Jones --                                                                   \n");
2102     MrBayesPrint ("                                                                                 \n");
2103     MrBayesPrint ("      Jones, D.T., W. R. Taylor, and J. M. Thornton. 1992. The rapid generation  \n");
2104     MrBayesPrint ("         of mutation data matrices from protein sequences. Comput. Appl.         \n");
2105     MrBayesPrint ("         Biosci. 8:275-282.                                                      \n");
2106     MrBayesPrint ("                                                                                 \n");
2107     MrBayesPrint ("      Dayhoff --                                                                 \n");
2108     MrBayesPrint ("                                                                                 \n");
2109     MrBayesPrint ("      Dayhoff, M.O., R.M. Schwartz, and B.C. Orcutt. 1978. A model of evol-      \n");
2110     MrBayesPrint ("         utionary change in proteins. Pp. 345-352 in Atlas of protein sequence   \n");
2111     MrBayesPrint ("         and structure. Vol. 5, Suppl. 3. National Biomedical Research           \n");
2112     MrBayesPrint ("          Foundation, Washington, D.C.                                           \n");
2113     MrBayesPrint ("                                                                                 \n");
2114     MrBayesPrint ("      Mtrev --                                                                   \n");
2115     MrBayesPrint ("                                                                                 \n");
2116     MrBayesPrint ("      Adachi, J. and M. Hasegawa. 1996. MOLPHY version 2.3: programs for         \n");
2117     MrBayesPrint ("         molecular phylogenetics based on maximum likelihood.  Computer Science  \n");
2118     MrBayesPrint ("         Monographs of Institute of Statistical Mathematics 28:1-150.            \n");
2119     MrBayesPrint ("                                                                                 \n");
2120     MrBayesPrint ("      Mtmam --                                                                   \n");
2121     MrBayesPrint ("                                                                                 \n");
2122     MrBayesPrint ("      Cao, Y., A. Janke, P.J. Waddell, M. Westerman, O. Takenaka, S. Murata,     \n");
2123     MrBayesPrint ("         N. Okada, S. Paabo, and M. Hasegawa. 1998. Conflict amongst individual  \n");
2124     MrBayesPrint ("         mitochondrial proteins in resolving the phylogeny of eutherian orders.  \n");
2125     MrBayesPrint ("         Journal of Molecular Evolution                                          \n");
2126     MrBayesPrint ("                                                                                 \n");
2127     MrBayesPrint ("      Yang, Z., R. Nielsen, and M. Hasegawa. 1998.  Models of amino acid         \n");
2128     MrBayesPrint ("         substitution and applications to mitochondrial protein evolution        \n");
2129     MrBayesPrint ("         Molecular Biology and Evolution 15:1600-1611.                           \n");
2130     MrBayesPrint ("                                                                                 \n");
2131     MrBayesPrint ("      WAG --                                                                     \n");
2132     MrBayesPrint ("                                                                                 \n");
2133     MrBayesPrint ("      Whelan, S. and Goldman, N. 2001. A general empirical model of protein      \n");
2134     MrBayesPrint ("         evolution derived from multiple protein families using a maximum-       \n");
2135     MrBayesPrint ("         likelihood approach. Molecular Biology and Evolution 18:691-699.        \n");
2136     MrBayesPrint ("                                                                                 \n");
2137     MrBayesPrint ("      Rtrev --                                                                   \n");
2138     MrBayesPrint ("                                                                                 \n");
2139     MrBayesPrint ("      Dimmic M.W., J.S. Rest, D.P. Mindell, and D. Goldstein. 2002. RArtREV:     \n");
2140     MrBayesPrint ("         An amino acid substitution matrix for inference of retrovirus and       \n");
2141     MrBayesPrint ("         reverse transcriptase phylogeny. Journal of Molecular Evolution         \n");
2142     MrBayesPrint ("         55: 65-73.                                                              \n");
2143     MrBayesPrint ("                                                                                 \n");
2144     MrBayesPrint ("      Cprev --                                                                   \n");
2145     MrBayesPrint ("                                                                                 \n");
2146     MrBayesPrint ("      Adachi, J., P. Waddell, W. Martin, and M. Hasegawa. 2000. Plastid          \n");
2147     MrBayesPrint ("         genome phylogeny and a model of amino acid substitution for proteins    \n");
2148     MrBayesPrint ("         encoded by chloroplast DNA. Journal of Molecular Evolution              \n");
2149     MrBayesPrint ("         50:348-358.                                                             \n");
2150     MrBayesPrint ("                                                                                 \n");
2151     MrBayesPrint ("      Blosum --                                                                  \n");
2152     MrBayesPrint ("                                                                                 \n");
2153     MrBayesPrint ("      Henikoff, S., and J. G. Henikoff. 1992. Amino acid substitution            \n");
2154     MrBayesPrint ("         matrices from protein blocks. Proc. Natl. Acad. Sci., U.S.A.            \n");
2155     MrBayesPrint ("         89:10915-10919. The matrix implemented in MrBayes is Blosum62.          \n");
2156     MrBayesPrint ("                                                                                 \n");
2157     MrBayesPrint ("      Vt --                                                                      \n");
2158     MrBayesPrint ("                                                                                 \n");
2159     MrBayesPrint ("      Muller, T., and M. Vingron. 2000. Modeling amino acid replacement.         \n");
2160     MrBayesPrint ("         Journal of Computational Biology 7:761-776.                             \n");
2161     MrBayesPrint ("                                                                                 \n");
2162     MrBayesPrint ("      LG --                                                                      \n");
2163     MrBayesPrint ("                                                                                 \n");
2164     MrBayesPrint ("      Le, Si Q. & Gascuel, O. 2008 An improved general amino- acid replacement   \n");
2165     MrBayesPrint ("         matrix. Mol. Biol. Evol. 25, 1307-1320.                                 \n");
2166     MrBayesPrint ("                                                                                 \n");
2167     MrBayesPrint ("   MrBayes implements a simple Jukes-Cantor-like model for restriction sites     \n");
2168     MrBayesPrint ("   and other binary data. A problem with some of these data is that there is a   \n");
2169     MrBayesPrint ("   coding bias, such that certain characters are missing from any observable     \n");
2170     MrBayesPrint ("   data matrix. It is impossible, for instance, to observe restriction sites that\n");
2171     MrBayesPrint ("   are absent in all the studied taxa. However, MrBayes corrects for this coding \n");
2172     MrBayesPrint ("   bias according to an idea described in                                        \n");
2173     MrBayesPrint ("                                                                                 \n");
2174     MrBayesPrint ("      Felsenstein, J. 1992. Phylogenies from restriction sites: A maximum-       \n");
2175     MrBayesPrint ("         likelihood approach. Evolution 46:159-173.                              \n");
2176     MrBayesPrint ("                                                                                 \n");
2177     MrBayesPrint ("                                                                                 \n");
2178     MrBayesPrint ("   The model used by MrBayes for 'standard' or morphological data is based on    \n");
2179     MrBayesPrint ("   the ideas originally presented by                                             \n");
2180     MrBayesPrint ("                                                                                 \n");
2181     MrBayesPrint ("      Lewis, P. O. 2001. A likelihood approach to estimating phylogeny from      \n");
2182     MrBayesPrint ("         discrete morphological character data. Systematic Biology 50:913-925.   \n");
2183     MrBayesPrint ("                                                                                 \n");
2184     MrBayesPrint ("                                                                                 \n");
2185     MrBayesPrint ("   For both DNA sequence and amino-acid data, the program allows rates to        \n");
2186     MrBayesPrint ("   change under a covarion-like model, first described by Tuffley and Steel      \n");
2187     MrBayesPrint ("                                                                                 \n");
2188     MrBayesPrint ("      Tuffley, C., and M. Steel. 1998. Modeling the covarion hypothesis          \n");
2189     MrBayesPrint ("         of nucleotide substitution. Mathematical Biosciences 147:63-91.         \n");
2190     MrBayesPrint ("                                                                                 \n");
2191     MrBayesPrint ("   and implemented by Huelsenbeck (2002)                                         \n");
2192     MrBayesPrint ("                                                                                 \n");
2193     MrBayesPrint ("      Huelsenbeck, J. P. 2002. Testing a covariotide model of DNA sub-           \n");
2194     MrBayesPrint ("         stitution. Molecular Biology and Evolution 19(5):698-707.               \n");
2195     MrBayesPrint ("                                                                                 \n");
2196     MrBayesPrint ("   Galtier (2001) implements a different variant of the covarion model in        \n");
2197     MrBayesPrint ("   a paper that is worth reading:                                                \n");
2198     MrBayesPrint ("                                                                                 \n");
2199     MrBayesPrint ("      Galtier, N. 2001. Maximum-likelihood phylogenetic analysis under a         \n");
2200     MrBayesPrint ("         covarion-like model. Mol. Biol. Evol. 18:866-873.                       \n");
2201     MrBayesPrint ("                                                                                 \n");
2202     MrBayesPrint ("                                                                                 \n");
2203     MrBayesPrint ("   A number of models are available that allow rates to vary                     \n");
2204     MrBayesPrint ("   across the characters. The program implements the proportion                  \n");
2205     MrBayesPrint ("   of invariable sites model and two variants of gamma distributed               \n");
2206     MrBayesPrint ("   rate variation. Yang\'s (1993) paper is a good one to cite for                \n");
2207     MrBayesPrint ("   implementing a gamma-distributed rates model. In the 1994 paper he            \n");
2208     MrBayesPrint ("   provides a way to approximate the continuous gamma distribution:              \n");
2209     MrBayesPrint ("                                                                                 \n");
2210     MrBayesPrint ("      Yang, Z. 1993. Maximum likelihood estimation of phylogeny from DNA         \n");
2211     MrBayesPrint ("         sequences when substitution rates differ over sites. Molecular          \n");
2212     MrBayesPrint ("         Biology and Evolution 10:1396-1401.                                     \n");
2213     MrBayesPrint ("                                                                                 \n");
2214     MrBayesPrint ("      Yang, Z. 1994. Maximum likelihood phylogenetic estimation from DNA         \n");
2215     MrBayesPrint ("         sequences with variable rates over sites: Approximate methods.          \n");
2216     MrBayesPrint ("         Journal of Molecular Evolution 39:306-314.                              \n");
2217     MrBayesPrint ("                                                                                 \n");
2218     MrBayesPrint ("   The program also implements Yang\'s autocorrelated gamma model. In            \n");
2219     MrBayesPrint ("   this model, the rate at one site depends to some extent on the rate at        \n");
2220     MrBayesPrint ("   an adjacent site. The appropriate citation for this model is:                 \n");
2221     MrBayesPrint ("                                                                                 \n");
2222     MrBayesPrint ("      Yang, Z. 1995. A space-time process model for the evolution of             \n");
2223     MrBayesPrint ("         DNA sequences. Genetics 139:993-1005.                                   \n");
2224     MrBayesPrint ("                                                                                 \n");
2225     MrBayesPrint ("                                                                                 \n");
2226     MrBayesPrint ("   The following two papers show how ancestral states on a tree can be recon-    \n");
2227     MrBayesPrint ("   structed. The Yang et al. paper implements an empirical Bayes approach while  \n");
2228     MrBayesPrint ("   Huelsenbeck and Bollback use a pure, hierarchical Bayes approach. The method  \n");
2229     MrBayesPrint ("   used in MrBayes is the latter, since it integrates over uncertainty in model  \n");
2230     MrBayesPrint ("   parameters.                                                                   \n");
2231     MrBayesPrint ("                                                                                 \n");
2232     MrBayesPrint ("      Yang, Z., S. Kumar, and M. Nei. 1995. A new method of inference of         \n");
2233     MrBayesPrint ("         ancestral nucleotide and amino acid sequences. Genetics 141:1641        \n");
2234     MrBayesPrint ("         1650.                                                                   \n");
2235     MrBayesPrint ("                                                                                 \n");
2236     MrBayesPrint ("      Huelsenbeck, J. P., and J. P. Bollback. 2001. Empirical and hier-          \n");
2237     MrBayesPrint ("         archical Bayesian estimation of ancestral states. Systematic            \n");
2238     MrBayesPrint ("         Biology 50:351-366.                                                     \n");
2239     MrBayesPrint ("                                                                                 \n");
2240     MrBayesPrint ("   You may also want to consult a more recent review of Bayesian reconstruction  \n");
2241     MrBayesPrint ("   of ancestral states and character evolution:                                  \n");
2242     MrBayesPrint ("                                                                                 \n");
2243     MrBayesPrint ("      Ronquist, F. 2004. Bayesian inference of character evolution. Trends in    \n");
2244     MrBayesPrint ("         Ecology and Evolution 19: 475-481.                                      \n");
2245     MrBayesPrint ("                                                                                 \n");
2246     MrBayesPrint ("                                                                                 \n");
2247     MrBayesPrint ("   MrBayes allows you to analyze gene tree - species tree problems using the     \n");
2248     MrBayesPrint ("   multi-species coalescent approach originally proposed by Edwards et al:       \n");
2249     MrBayesPrint ("                                                                                 \n");
2250     MrBayesPrint ("      Edwards, S., L. Liu, and D. Pearl. 2007. High-resolution species trees     \n");
2251     MrBayesPrint ("         without concatenation. Proc. Natl. Acad. Sci. USA 104: 5936-5941.       \n");
2252     MrBayesPrint ("                                                                                 \n");
2253     MrBayesPrint ("                                                                                 \n");
2254     MrBayesPrint ("   The program implements an incredibly parameter rich model, first described    \n");
2255     MrBayesPrint ("   by Tuffley and Steel (1997), that orders trees in the same way as the         \n");
2256     MrBayesPrint ("   so-called parsimony method of phylogenetic inference. The appropriate         \n");
2257     MrBayesPrint ("   citation is:                                                                  \n");
2258     MrBayesPrint ("                                                                                 \n");
2259     MrBayesPrint ("      Tuffley, C., and M. Steel. 1997. Links between maximum likelihood          \n");
2260     MrBayesPrint ("         and maximum parsimony under a simple model of site substitution.        \n");
2261     MrBayesPrint ("         Bull. Math. Bio. 59:581-607.                                            \n");
2262     MrBayesPrint ("                                                                                 \n");
2263     MrBayesPrint ("                                                                                 \n");
2264     MrBayesPrint ("   MrBayes implements three relaxed clock models: the Compound Poisson Process   \n");
2265     MrBayesPrint ("   (CPP), the Thorne-Kishino 2002 (TK02), and the Independent Gamma Rates (IGR)  \n");
2266     MrBayesPrint ("   models. The CPP model was first described by Huelsenbeck et al. (2000). It    \n");
2267     MrBayesPrint ("   is an autocorrelated discrete model of rate variation over time. Instead of   \n");
2268     MrBayesPrint ("   the modified gamma distribution originally proposed for the rate multipliers, \n");
2269     MrBayesPrint ("   MrBayes uses a lognormal distribution. The extensions necessary to sample over\n");
2270     MrBayesPrint ("   tree space under this model are original to MrBayes; the original paper only  \n");
2271     MrBayesPrint ("   considered fixed trees.                                                       \n");
2272     MrBayesPrint ("                                                                                 \n");
2273     MrBayesPrint ("   The TK02 model was first described by Thorne and Kishino (2002), and is a     \n");
2274     MrBayesPrint ("   variant of a model presented by them earlier (Thorne et al., 1998). It is an  \n");
2275     MrBayesPrint ("   autocorrelated continuous model, in which rates vary according to a lognormal \n");
2276     MrBayesPrint ("   distribution. Specifically, the rate of a descendant node is assumed to be    \n");
2277     MrBayesPrint ("   drawn from a lognormal distribution with the mean being the rate of the an-   \n");
2278     MrBayesPrint ("   cestral node, and the variance being proportional to the length of the branch \n");
2279     MrBayesPrint ("   separating the nodes (measured in terms of expected substitutions per site at \n");
2280     MrBayesPrint ("   the base rate of the clock).                                                  \n");
2281     MrBayesPrint ("                                                                                 \n");
2282     MrBayesPrint ("   The final relaxed clock model is the IGR model, in which branch rates are     \n");
2283     MrBayesPrint ("   modeled as being drawn independently from gamma distributions. The model was  \n");
2284     MrBayesPrint ("   originally described in the literature as the 'White Noise' model by Lepage   \n");
2285     MrBayesPrint ("   et al. (2007), but the original MrBayes implementation predates that paper.   \n");
2286     MrBayesPrint ("   The IGR model is closely related to the uncorrelated gamma model presented    \n");
2287     MrBayesPrint ("   originally by Drummond et al. (2006), but it is more elegant in that it truly \n");
2288     MrBayesPrint ("   lacks time structure. See Lepage et al. (2007) for details.                   \n");
2289     MrBayesPrint ("                                                                                 \n");
2290     MrBayesPrint ("      Huelsenbeck, J. P., B. Larget, and D. Swofford. 2000. A compound Poisson   \n");
2291     MrBayesPrint ("         process for relaxing the molecular clock. Genetics 154: 1879-1892.      \n");
2292     MrBayesPrint ("                                                                                 \n");
2293     MrBayesPrint ("      Thorne, J. L., H. Kishino, and I. S. Painter. 1998. Estimating the rate    \n");
2294     MrBayesPrint ("         of evolution of the rate of molecular evolution. Mol. Biol. Evol.       \n");
2295     MrBayesPrint ("         15: 1647-1657.                                                          \n");
2296     MrBayesPrint ("                                                                                 \n");
2297     MrBayesPrint ("      Thorne, J. L., and H. Kishino. 2002. Divergence time and evolutionary      \n");
2298     MrBayesPrint ("         rate estimation with multilocus data. Syst. Biol. 51: 689-702.          \n");
2299     MrBayesPrint ("                                                                                 \n");
2300     MrBayesPrint ("      Drummond, A. J., S. Y. W. Ho, M. J. Phillips, and A. Rambaut. 2006.        \n");
2301     MrBayesPrint ("         Relaxed phylogenetics and dating with confidence. PLoS Biology          \n");
2302     MrBayesPrint ("         4: 699-710.                                                             \n");
2303     MrBayesPrint ("                                                                                 \n");
2304     MrBayesPrint ("      Lepage, T., D. Bryant, H. Philippe, and N. Lartillot. 2007. A general      \n");
2305     MrBayesPrint ("         comparison of relaxed molecular clock models. Mol. Biol. Evol.          \n");
2306     MrBayesPrint ("         24: 2669-2680.                                                          \n");
2307     MrBayesPrint ("                                                                                 \n");
2308     MrBayesPrint ("                                                                                 \n");
2309     MrBayesPrint ("   The standard tree proposals used by MrBayes are described by Lakner et al.    \n");
2310     MrBayesPrint ("   (2008). The parsimony-biased tree proposals are still undescribed, although   \n");
2311     MrBayesPrint ("   a rough outline of the idea is presented in the same paper.                   \n");
2312     MrBayesPrint ("                                                                                 \n");
2313     MrBayesPrint ("      Lakner, C., P. van der Mark, J. P. Huelsenbeck, B. Larget, and F. Ronquist.\n");
2314     MrBayesPrint ("         2008. Efficiency of Markov chain Monte Carlo tree proposals in Bayesian \n");
2315     MrBayesPrint ("         phylogenetics. Syst. Biol. 57: 86-103.                                  \n");
2316     MrBayesPrint ("                                                                                 \n");
2317     MrBayesPrint ("                                                                                 \n");
2318     MrBayesPrint ("   The topology convergence diagnostic used by MrBayes, the average standard     \n");
2319     MrBayesPrint ("   deviation of split frequencies, is described by Lakner et al. (2008). The     \n");
2320     MrBayesPrint ("   potential scale reduction factor, the diagnostic used by MrBayes for contin-  \n");
2321     MrBayesPrint ("   uous parameters, was first proposed by Gelman and Rubin (1992). The auto-     \n");
2322     MrBayesPrint ("   tuning mechanism used in MrBayes is based on a paper by Roberts and Rosenthal \n");
2323     MrBayesPrint ("   (2009).                                                                       \n");
2324     MrBayesPrint ("                                                                                 \n");
2325     MrBayesPrint ("      Gelman, A., and D. B. Rubin. 1992. Inference from iterative simulation     \n");
2326     MrBayesPrint ("         using multiple sequences. Statistical Science 7: 457-472.               \n");
2327     MrBayesPrint ("         Bull. Math. Bio. 59:581-607.                                            \n");
2328     MrBayesPrint ("                                                                                 \n");
2329     MrBayesPrint ("      Lakner, C., P. van der Mark, J. P. Huelsenbeck, B. Larget, and F. Ronquist.\n");
2330     MrBayesPrint ("         2008. Efficiency of Markov chain Monte Carlo tree proposals in Bayesian \n");
2331     MrBayesPrint ("         phylogenetics. Syst. Biol. 57: 86-103.                                  \n");
2332     MrBayesPrint ("                                                                                 \n");
2333     MrBayesPrint ("      Roberts, G. O., and J. S. Rosenthal. 2009. Examples of adaptive MCMC. Jour-\n");
2334     MrBayesPrint ("         nal of Compuational and Graphical Statistics 18: 349-367.               \n");
2335     MrBayesPrint ("                                                                                 \n");
2336     MrBayesPrint ("                                                                                 \n");
2337     MrBayesPrint ("   The harmonic mean estimator of model likelihoods, used for Bayes factor tes-  \n");
2338     MrBayesPrint ("   ting, was discussed by Newton and Raftery (1996). The more accurate stepping- \n");
2339     MrBayesPrint ("   stone algorithm was first proposed by Xie et al. (2011). The paper by         \n");
2340     MrBayesPrint ("   Lartillot and Philippe (2006) presents an interesting discussion of the       \n");
2341     MrBayesPrint ("   shortcomings of the harmonic mean estimator and describes thermodynamic       \n");
2342     MrBayesPrint ("   integration, a technique that is similar to the stepping-stone algorithm.     \n");
2343     MrBayesPrint ("                                                                                 \n");
2344     MrBayesPrint ("      Newton, M. A., and A. E. Raftery. 1994. Approcimate Bayesian inference     \n");
2345     MrBayesPrint ("         with the weighted likelihood bootstrap. J. R. Stat. Soc. B. 56. 3-48.   \n");
2346     MrBayesPrint ("                                                                                 \n");
2347     MrBayesPrint ("      Lartillot, N., and H. Philippe. 2006. Computing Bayes factors using        \n");
2348     MrBayesPrint ("         thermodynamic integration. Syst. Biol. 55: 195-207.                     \n");
2349     MrBayesPrint ("                                                                                 \n");
2350     MrBayesPrint ("      Xie, W., P. O. Lewis, Y. Fan, L. Kuo, and M.-H. Chen. 2011. Improving      \n");
2351     MrBayesPrint ("         marginal likelihood estimation for Bayesian phylogenetic model          \n");
2352     MrBayesPrint ("         selection. Syst. Biol. 60: 150-160.                                     \n");
2353     MrBayesPrint ("                                                                                 \n");
2354     MrBayesPrint ("                                                                                 \n");
2355     MrBayesPrint ("   For unconstrained branch lengths, MrBayes implements the compound Dirichlet   \n");
2356     MrBayesPrint ("   priors for branch lengths described by Rannala et al. (2012) and Zhang et al. \n");
2357     MrBayesPrint ("   (2012). Compared with the i.i.d. exponential and uniform priors for branch    \n");
2358     MrBayesPrint ("   lengthes in the previous versions of MrBayes, the Dirichlet priors appear more\n");
2359     MrBayesPrint ("   reasonable and may avoid the problem of extremely long trees, as discussed by \n");
2360     MrBayesPrint ("   Brown et al. (2010) and Marshall (2010). The two-exponential prior on internal\n");
2361     MrBayesPrint ("   and external branch lengths described by Yang & Rannala (2005) and Yang (2007)\n");
2362     MrBayesPrint ("   is also implemented in this version.                                          \n");
2363     MrBayesPrint ("                                                                                 \n");
2364     MrBayesPrint ("      Brown, J. M., S. M. Hedtke, A. R. Lemmon, and E. M. Lemmon. 2010. When     \n");
2365     MrBayesPrint ("         trees  grow too long: investigating the causes of highly inaccurate     \n");
2366     MrBayesPrint ("         Bayesian branch-length estimates. Syst. Biol. 59:145-161.               \n");
2367     MrBayesPrint ("                                                                                 \n");
2368     MrBayesPrint ("      Marshall, D. C. 2010. Cryptic failure of partitioned Bayesian phylogenetic \n");
2369     MrBayesPrint ("         analyses: lost in the land of long trees. Syst. Biol. 59:108-117.       \n");
2370     MrBayesPrint ("                                                                                 \n");
2371     MrBayesPrint ("      Rannala, B., T. Zhu, and Z. Yang. 2012. Tail paradox, partial              \n");
2372     MrBayesPrint ("         identifiability and influential priors in Bayesian branch length        \n");
2373     MrBayesPrint ("         inference. Mol. Biol. Evol. 29:325-335.                                 \n");
2374     MrBayesPrint ("                                                                                 \n");
2375     MrBayesPrint ("      Zhang, C., B. Rannala, and Z. Yang. 2012. Robustness of compound Dirichlet \n");
2376     MrBayesPrint ("         priors for Bayesian inference of branch lengths. Syst. Biol. 61:779-784.\n");
2377     MrBayesPrint ("                                                                                 \n");
2378     MrBayesPrint ("      Yang, Z. 2007. Fair-balance paradox, star-tree paradox and Bayesian        \n");
2379     MrBayesPrint ("         phylogenetics. Mol. Biol. Evol. 24:1639-1655.                           \n");
2380     MrBayesPrint ("                                                                                 \n");
2381     MrBayesPrint ("      Yang, Z., and B. Rannala. 2005. Branch-length prior influences Bayesian    \n");
2382     MrBayesPrint ("         posterior probability of phylogeny. Syst. Biol. 54:455-470.             \n");
2383     MrBayesPrint ("                                                                                 \n");
2384     MrBayesPrint ("                                                                                 \n");
2385     MrBayesPrint ("                                                                                 \n");
2386     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
2387
2388     return (NO_ERROR);
2389 }
2390
2391
2392 int DoConstraint (void)
2393 {
2394     int         i, howMany;
2395     int         *tset;
2396
2397     if (consrtainType == PARTIAL)
2398         tset=tempSetNeg;
2399     else
2400         tset=tempSet;
2401
2402     /* add set to tempSet */
2403     if (fromI >= 0 && toJ < 0)
2404         {
2405         if (AddToGivenSet (fromI, toJ, everyK, 1, tset) == ERROR)
2406             return (ERROR);
2407         }
2408     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
2409         {
2410         if (AddToGivenSet (fromI, toJ, everyK, 1, tset) == ERROR)
2411             return (ERROR);
2412         }
2413     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
2414         {
2415         if (AddToGivenSet (fromI, toJ, everyK, 1, tset) == ERROR)
2416             return (ERROR);
2417         }
2418             
2419     /* check that this is not a stupid constraint */
2420     howMany = 0;
2421     for (i=0; i<numTaxa; i++)
2422         if (tempSet[i] != 0)
2423             howMany++;
2424
2425     if (howMany == 0)
2426         {
2427         MrBayesPrint ("%s   This constraint does not include any taxa and will not be defined\n", spacer);
2428         return (ERROR);
2429         }
2430
2431     if (consrtainType == HARD)
2432         {
2433         if (howMany == numTaxa)
2434             {
2435             /* We allow this so we can report states from and calibrate root */
2436             }
2437         
2438         } /*end consrtainType == HARD */
2439     else if (consrtainType == PARTIAL)
2440         {
2441         if (howMany == 1)
2442             {
2443             MrBayesPrint ("%s   This partial constraint include only one taxa. It is alwayes satisfied and will not be defined.\n", spacer);
2444             return (ERROR);
2445             }
2446
2447         howMany = 0;
2448         for (i=0; i<numTaxa; i++)
2449             {
2450             if (tempSetNeg[i] != 0)
2451                 {
2452                 howMany++;
2453                 if (tempSetNeg[i] == tempSet[i])
2454                     {
2455                     MrBayesPrint ("%s   Two sets of taxa in partial constraint are not allowed to intersect. Constraint will not be defined\n", spacer);
2456                     return (ERROR);
2457                     }
2458                 }
2459             }
2460         if (howMany == 0)
2461             {
2462             MrBayesPrint ("%s   This partial constraint does not include any taxa in the second set and will not be defined\n", spacer);
2463             return (ERROR);
2464             }
2465         }
2466     else if (consrtainType == NEGATIVE)
2467         {
2468         if (howMany == 1)
2469             {
2470             MrBayesPrint ("%s   Negative constraint should include more than one taxa. Constraint will not be defined\n", spacer);
2471             return (ERROR);
2472             }
2473         }
2474
2475     /* add name to constraintNames */
2476     if (AddString (&constraintNames, numDefinedConstraints, tempSetName) == ERROR)
2477         {
2478         MrBayesPrint ("%s   Problem adding constraint %s to list\n", spacer, tempSetName);
2479         return (ERROR);
2480         }
2481
2482     /* store tempSet */
2483     AddBitfield (&definedConstraint, numDefinedConstraints, tempSet, numTaxa);
2484     if (consrtainType == PARTIAL)
2485         {
2486         AddBitfield (&definedConstraintTwo, numDefinedConstraints, tempSetNeg, numTaxa);
2487         }
2488     else
2489         {
2490         definedConstraintTwo = (BitsLong **) SafeRealloc ((void *)(definedConstraintTwo), ((size_t)numDefinedConstraints+1)*sizeof(BitsLong *));
2491         if (definedConstraintTwo==NULL)
2492             return ERROR;
2493         definedConstraintTwo[numDefinedConstraints]=NULL;
2494         }
2495     
2496     /* add a default node calibration */
2497     nodeCalibration = (Calibration *) SafeRealloc ((void *)nodeCalibration, ((size_t)numDefinedConstraints+1)*sizeof(Calibration));
2498     nodeCalibration[numDefinedConstraints].prior            = defaultCalibration.prior;
2499     nodeCalibration[numDefinedConstraints].priorParams[0]   = defaultCalibration.priorParams[0];
2500     nodeCalibration[numDefinedConstraints].priorParams[1]   = defaultCalibration.priorParams[1];
2501     nodeCalibration[numDefinedConstraints].priorParams[2]   = defaultCalibration.priorParams[2];
2502     nodeCalibration[numDefinedConstraints].min              = defaultCalibration.min;
2503     nodeCalibration[numDefinedConstraints].max              = defaultCalibration.max;
2504     nodeCalibration[numDefinedConstraints].LnPriorProb      = defaultCalibration.LnPriorProb;
2505     nodeCalibration[numDefinedConstraints].LnPriorRatio     = defaultCalibration.LnPriorRatio;
2506     strcpy(nodeCalibration[numDefinedConstraints].name, defaultCalibration.name);
2507
2508     /* increment number of defined constraints */
2509     numDefinedConstraints++;
2510
2511     /* reallocate and initialize space for activeConstraints */
2512     for (i=0; i<numCurrentDivisions; i++)
2513         {
2514         modelParams[i].activeConstraints = (int *) SafeRealloc((void *)(modelParams[i].activeConstraints), (size_t)numDefinedConstraints*sizeof(int));
2515         modelParams[i].activeConstraints[numDefinedConstraints-1] = NO;
2516         }
2517
2518     /* reallocate and initialize space for tempActiveConstraints */
2519     tempActiveConstraints = (int *) SafeRealloc((void *)(tempActiveConstraints), (size_t)numDefinedConstraints*sizeof(int));
2520     tempActiveConstraints[numDefinedConstraints-1] = NO;
2521
2522     definedConstraintsType = (enum ConstraintType *) SafeRealloc((void *)(definedConstraintsType), (size_t)numDefinedConstraints*sizeof(enum ConstraintType));
2523     if (definedConstraintsType==NULL)
2524         return ERROR;
2525     definedConstraintsType[numDefinedConstraints-1] = consrtainType;
2526
2527     definedConstraintPruned = (BitsLong **) SafeRealloc ((void *)(definedConstraintPruned), (size_t)numDefinedConstraints*sizeof(BitsLong *));
2528     if (definedConstraintPruned==NULL)
2529         return ERROR;
2530     definedConstraintPruned[numDefinedConstraints-1]=NULL;
2531
2532     definedConstraintTwoPruned = (BitsLong **) SafeRealloc ((void *)(definedConstraintTwoPruned), (size_t)numDefinedConstraints*sizeof(BitsLong *));
2533     if (definedConstraintTwoPruned==NULL)
2534         return ERROR;
2535     definedConstraintTwoPruned[numDefinedConstraints-1]=NULL;
2536
2537     /* show taxset (for debugging) */
2538     // for (i=0; i<numTaxa; i++)
2539     //     MrBayesPrint ("%4d  %4d\n", i+1, taxaInfo[i].constraints[numDefinedConstraints-1]);
2540
2541     return (NO_ERROR);
2542 }
2543
2544
2545 int DoConstraintParm (char *parmName, char *tkn)
2546 {
2547     int         i, index, tempInt;
2548     MrBFlt      tempD;
2549     static int  *tempSetCurrent;
2550     
2551     if (defMatrix == NO)
2552         {
2553         MrBayesPrint ("%s   A matrix must be specified before constraints can be defined\n", spacer);
2554         return (ERROR);
2555         }
2556
2557     if (expecting == Expecting(PARAMETER))
2558         {
2559         if (!strcmp(parmName, "Xxxxxxxxxx"))
2560             {
2561             /* check size of constraint name */
2562             if (strlen(tkn) > 99)
2563                 {
2564                 MrBayesPrint ("%s   Constraint name is too long\n", spacer);
2565                 return (ERROR);
2566                 }
2567                 
2568             /* check to see if the name has already been used as a constraint */
2569             if (numDefinedConstraints > 0)
2570                 {
2571                 if (CheckString (constraintNames, numDefinedConstraints, tkn, &index) == ERROR)
2572                     {
2573                     /* an ERROR returned if the constraint name has not been used. we _want_ to be here */
2574                     }
2575                 else
2576                     {
2577                     MrBayesPrint ("%s   Constraint name '%s' has been used previously\n", spacer, tkn);
2578                     return (ERROR);
2579                     }
2580                 }
2581                 
2582             /* copy the name to the temporary constraint names string */
2583             strcpy (tempSetName, tkn);
2584             
2585             /* clear tempSet */
2586             for (i=0; i<numTaxa; i++)
2587                 tempSet[i] = 0;
2588
2589             consrtainType = HARD; /* set default constrain type */
2590             tempSetCurrent=tempSet;
2591             fromI = toJ = everyK = -1;
2592             foundDash = foundSlash = NO;
2593             MrBayesPrint ("%s   Defining constraint called '%s'\n", spacer, tkn);
2594             foundExp = NO;
2595             foundFirst = YES;
2596             foundEqual = NO;
2597             isNegative = NO;
2598             foundColon = NO;
2599             expecting = Expecting(ALPHA);
2600             expecting |= Expecting(NUMBER);
2601             expecting |= Expecting(DASH);
2602             expecting |= Expecting(EQUALSIGN);
2603             }
2604         else
2605             return (ERROR);
2606         }
2607     else if (expecting == Expecting(EQUALSIGN))
2608         {
2609         foundEqual = YES;
2610         expecting  = Expecting(ALPHA);
2611         expecting |= Expecting(NUMBER);
2612         }
2613     else if (expecting == Expecting(LEFTPAR))
2614         {
2615         isNegative = NO;
2616         expecting = Expecting(NUMBER);
2617         expecting |= Expecting(DASH);
2618         }
2619     else if (expecting == Expecting(RIGHTPAR))
2620         {
2621         isNegative = NO;
2622         foundExp = NO;
2623         expecting = Expecting(EQUALSIGN);
2624         }
2625     else if (expecting == Expecting(DASH))
2626         {
2627         if (foundExp == YES)
2628             isNegative = YES;
2629         else
2630             foundDash = YES;
2631         expecting = Expecting(NUMBER);
2632         }
2633     else if (expecting == Expecting(ALPHA))
2634         {
2635         if (foundFirst == YES && foundEqual == NO)
2636             {
2637             /* We are filling in the probability for the constraint. Specifically, we expect exp(number). */
2638             if (IsSame ("Partial", tkn) == SAME)
2639                 {
2640                 for (i=0; i<numTaxa; i++)
2641                     tempSetNeg[i] = 0;
2642
2643                 consrtainType = PARTIAL;
2644                 expecting = Expecting(EQUALSIGN);
2645                 expecting |= Expecting(ALPHA);
2646                 }
2647             else if (IsSame ("Hard", tkn) == SAME)
2648                 {
2649                 consrtainType = HARD;
2650                 expecting = Expecting(EQUALSIGN);
2651                 expecting |= Expecting(ALPHA);
2652                 }
2653             else if (IsSame ("Negative", tkn) == SAME)
2654                 {
2655                 consrtainType = NEGATIVE;
2656                 expecting = Expecting(EQUALSIGN);
2657                 expecting |= Expecting(ALPHA);
2658                 }
2659             else if (IsSame ("Exp", tkn) == SAME || IsSame ("Exp", tkn) == CONSISTENT_WITH)
2660                 {
2661                 foundExp = YES;
2662                 foundDash = NO;
2663                 isNegative = NO;
2664                 expecting  = Expecting(LEFTPAR);
2665                 }
2666             else
2667                 {
2668                 MrBayesPrint ("%s   Do not understand %s\n", spacer, tkn);
2669                 return (ERROR);
2670                 }
2671             }
2672         else
2673             {
2674             /* We are defining a constraint in terms of a taxon set (called tkn, here) or we are referring to
2675                the taxon name. We should be able to find tkn in the list of taxon set names or in the list
2676                of taxon names. If we cannot, then we have a problem and return an error. */
2677             if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
2678                 {
2679                 if (numTaxaSets < 1)
2680                     {
2681                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
2682                     return (ERROR);
2683                     }
2684                 if (CheckString (taxaSetNames, numTaxaSets, tkn, &index) == ERROR)
2685                     {
2686                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
2687                     return (ERROR);
2688                     }
2689                 /* add taxa from taxset tkn to new tempSet */
2690                 for (i=0; i<numTaxa; i++)
2691                     {
2692                     if (IsBitSet(i, taxaSet[index]) == YES)
2693                         {
2694                         tempSetCurrent[i] = 1;
2695                         }
2696                     }
2697                 }
2698             else
2699                 {
2700                 tempSetCurrent[index] = 1;
2701                 }
2702             fromI = toJ = everyK = -1;
2703
2704             expecting  = Expecting(ALPHA);
2705             expecting |= Expecting(NUMBER);
2706             if (consrtainType != PARTIAL || foundColon == YES)
2707                 expecting |= Expecting(SEMICOLON);
2708             else
2709                 expecting |= Expecting(COLON);
2710             }
2711         }
2712     else if (expecting == Expecting(NUMBER))
2713         {
2714         if (foundFirst == YES && foundEqual == NO)
2715             {
2716             /* We are filling in the probability for the constraint. Specifically, we expect number. */
2717             sscanf (tkn, "%lf", &tempD);        
2718             if (foundExp == NO && tempD < 0.0)
2719                 {
2720                 MrBayesPrint ("%s   The probability of a clade cannot be less than zero\n", spacer, tkn);
2721                 return (ERROR);
2722                 }
2723             if (isNegative == YES || foundDash == YES)
2724                 tempD *= -1.0;
2725             if (foundExp == YES)
2726                 {
2727                 expecting  = Expecting(RIGHTPAR);
2728                 }
2729             else
2730                 {
2731                 expecting  = Expecting(EQUALSIGN);
2732                 }
2733             foundFirst = NO;
2734             foundDash = NO;
2735             }
2736         else
2737             {       
2738             if (strlen(tkn) == 1 && !strcmp(tkn, "."))
2739                 {
2740                 tempInt = numTaxa;
2741                 }
2742             else
2743                 {
2744                 sscanf (tkn, "%d", &tempInt);
2745                 if (tempInt <= 0 || tempInt > numTaxa)
2746                     {
2747                     MrBayesPrint ("%s   Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa);
2748                     return (ERROR);
2749                     }
2750                 }
2751             tempInt--;
2752             if (foundDash == YES)
2753                 {
2754                 if (fromI >= 0)
2755                     toJ = tempInt;
2756                 else
2757                     {
2758                     MrBayesPrint ("%s   Improperly formatted constraint\n", spacer);
2759                     return (ERROR);
2760                     }
2761                 foundDash = NO;
2762                 }
2763             else if (foundSlash == YES)
2764                 {
2765                 tempInt++;
2766                 if (tempInt <= 1)
2767                     {
2768                     MrBayesPrint ("%s   Improperly formatted constraint\n", spacer);
2769                     return (ERROR);
2770                     }
2771                 if (fromI >= 0 && toJ >= 0 && fromI < toJ)
2772                     everyK = tempInt;
2773                 else
2774                     {
2775                     MrBayesPrint ("%s   Improperly formatted constraint\n", spacer);
2776                     return (ERROR);
2777                     }
2778                 foundSlash = NO;
2779                 }
2780             else
2781                 {
2782                 if (fromI >= 0 && toJ < 0)
2783                     {
2784                     if (AddToGivenSet (fromI, toJ, everyK, 1, tempSetCurrent) == ERROR)
2785                         return (ERROR);
2786                     fromI = tempInt;
2787                     }
2788                 else if (fromI < 0 && toJ < 0)
2789                     {
2790                     fromI = tempInt;
2791                     }
2792                 else if (fromI >= 0 && toJ >= 0 && everyK < 0)
2793                     {
2794                     if (AddToGivenSet (fromI, toJ, everyK, 1, tempSetCurrent) == ERROR)
2795                         return (ERROR);
2796                     fromI = tempInt;
2797                     toJ = everyK = -1;
2798                     }
2799                 else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
2800                     {
2801                     if (AddToGivenSet (fromI, toJ, everyK, 1, tempSetCurrent) == ERROR)
2802                         return (ERROR);
2803                     fromI = tempInt;
2804                     toJ = everyK = -1;
2805                     }
2806                 else
2807                     {
2808                     MrBayesPrint ("%s   Improperly formatted constraint\n", spacer);
2809                         {
2810                         return (ERROR);
2811                         }
2812                     }
2813                 }
2814
2815             expecting  = Expecting(ALPHA);
2816             expecting |= Expecting(NUMBER);
2817             expecting |= Expecting(DASH);
2818             expecting |= Expecting(BACKSLASH);
2819             if (consrtainType != PARTIAL || foundColon == YES)
2820                 expecting |= Expecting(SEMICOLON);
2821             else
2822                 expecting |= Expecting(COLON);
2823             }
2824         }
2825     else if (expecting == Expecting(BACKSLASH))
2826         {
2827         foundSlash = YES;
2828         expecting = Expecting(NUMBER);
2829         }
2830     else if (expecting == Expecting(COLON))
2831         {
2832         if (foundColon == YES)
2833             {
2834             MrBayesPrint ("%s   Improperly formatted constraint: two colon charactors in constraint command.\n", spacer);
2835             return (ERROR);
2836             }
2837
2838         /* add set to tempSet */
2839         if (fromI >= 0 && toJ < 0)
2840             {
2841             if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2842                 return (ERROR);
2843             }
2844         else if (fromI >= 0 && toJ >= 0 && everyK < 0)
2845             {
2846             if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2847                 return (ERROR);
2848             }
2849         else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
2850             {
2851             if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2852                 return (ERROR);
2853             }
2854         fromI = toJ = everyK = -1;
2855         foundDash = foundSlash = NO;
2856
2857         foundColon = YES;
2858         tempSetCurrent = tempSetNeg;
2859         expecting  = Expecting(ALPHA);
2860         expecting |= Expecting(NUMBER);
2861         }
2862     else
2863         return (ERROR);
2864
2865     return (NO_ERROR);
2866 }
2867
2868
2869 int DoCtype (void)
2870 {
2871     int         i, foundIllegal, marks[5], numAppliedTo;
2872
2873     /* add set to tempSet */
2874     if (fromI >= 0 && toJ < 0)
2875         {
2876         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2877             return (ERROR);
2878         }
2879     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
2880         {
2881         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2882             return (ERROR);
2883         }
2884     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
2885         {
2886         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
2887             return (ERROR);
2888         }
2889         
2890     /* merge tempSet with ctype */
2891     numAppliedTo = 0;
2892     for (i=0; i<5; i++)
2893         marks[i] = NO;
2894     for (i=0; i<numChar; i++)
2895         {
2896         if (tempSet[i] != 0)
2897             {
2898             foundIllegal = NO;
2899             if (charOrdering != UNORD)
2900                 {
2901                 if (charInfo[i].charType == DNA)
2902                     {
2903                     foundIllegal = YES;
2904                     if (marks[0] == NO)
2905                         MrBayesPrint ("%s   Ctype not applied to DNA states which must be unordered\n", spacer);
2906                     marks[0] = YES;
2907                     }
2908                 else if (charInfo[i].charType == RNA)
2909                     {
2910                     foundIllegal = YES;
2911                     if (marks[1] == NO)
2912                         MrBayesPrint ("%s   Ctype not applied to RNA states which must be unordered\n", spacer);
2913                     marks[1] = YES;
2914                     }
2915                 else if (charInfo[i].charType == PROTEIN)
2916                     {
2917                     foundIllegal = YES;
2918                     if (marks[2] == NO)
2919                         MrBayesPrint ("%s   Ctype not applied to amino acid states which must be unordered\n", spacer);
2920                     marks[2] = YES;
2921                     }
2922                 else if (charInfo[i].charType == RESTRICTION)
2923                     {
2924                     foundIllegal = YES;
2925                     if (marks[3] == NO)
2926                         MrBayesPrint ("%s   Ctype not applied to restriction site states which must be unordered\n", spacer);
2927                     marks[3] = YES;
2928                     }
2929                 else if (charInfo[i].charType == CONTINUOUS)
2930                     {
2931                     foundIllegal = YES;
2932                     if (marks[4] == NO)
2933                         MrBayesPrint ("%s   Ctype not applied to continuous characters\n", spacer);
2934                     marks[4] = YES;
2935                     }
2936                 }
2937             if (foundIllegal == NO)
2938                 {
2939                 charInfo[i].ctype = charOrdering;
2940                 numAppliedTo++;
2941                 }
2942             }
2943         }
2944     if (numAppliedTo > 0)
2945         {
2946         MrBayesPrint ("%s   Ctype was applied to %d standard characters\n", spacer, numAppliedTo);
2947         }
2948     else
2949         {
2950         MrBayesPrint ("%s   No standard characters found to apply ctype to\n", spacer);
2951         }
2952     
2953 #   if 0
2954     for (i=0; i<numChar; i++)
2955         MrBayesPrint ("%4d -- %d\n", i, ctype[i]);
2956 #   endif
2957
2958     return (NO_ERROR);
2959 }
2960
2961
2962 int DoCtypeParm (char *parmName, char *tkn)
2963 {
2964     int     i, index, tempInt;
2965     
2966     if (defMatrix == NO)
2967         {
2968         MrBayesPrint ("%s   A matrix must be specified before typesets can be defined\n", spacer);
2969         return (ERROR);
2970         }
2971
2972     if (expecting == Expecting(PARAMETER))
2973         {
2974         if (!strcmp(parmName, "Xxxxxxxxxx"))
2975             {
2976             if (IsSame ("Ordered", tkn) == SAME || IsSame ("Ordered", tkn) == CONSISTENT_WITH)
2977                 charOrdering = ORD;
2978             else if (IsSame ("Unordered", tkn) == SAME || IsSame ("Unordered", tkn) == CONSISTENT_WITH)
2979                 charOrdering = UNORD;
2980             else if (IsSame ("Dollo", tkn) == SAME || IsSame ("Dollo", tkn) == CONSISTENT_WITH)
2981                 charOrdering = DOLLO;
2982             else if (IsSame ("Irreversible", tkn) == SAME || IsSame ("Irreversible", tkn) == CONSISTENT_WITH)
2983                 charOrdering = IRREV;
2984             else
2985                 {
2986                 MrBayesPrint ("%s   Do not understand delimiter \"%s\"\n", spacer, tkn);
2987                 return (ERROR);
2988                 }
2989             
2990             /* clear tempSet */
2991             for (i=0; i<numChar; i++)
2992                 tempSet[i] = 0;
2993             
2994             fromI = toJ = everyK = -1;
2995             foundDash = foundSlash = NO;
2996             MrBayesPrint ("%s   Setting characters to %s\n", spacer, tkn);
2997             expecting = Expecting(COLON);
2998             }
2999         else
3000             return (ERROR);
3001         }
3002     else if (expecting == Expecting(COLON))
3003         {
3004         expecting  = Expecting(ALPHA) | Expecting(NUMBER);
3005         }
3006     else if (expecting == Expecting(ALPHA))
3007         {
3008         /* first, check that we are not trying to put in another character ordering */
3009         if (IsSame ("Ordered", tkn) == SAME || IsSame ("Ordered", tkn) == CONSISTENT_WITH)
3010             {
3011             MrBayesPrint ("%s   You cannot specify more than one ordering with a single use of ctype\n", spacer, tkn);
3012             return (ERROR);
3013             }
3014         else if (IsSame ("Unordered", tkn) == SAME || IsSame ("Unordered", tkn) == CONSISTENT_WITH)
3015             {
3016             MrBayesPrint ("%s   You cannot specify more than one ordering with a single use of ctype\n", spacer, tkn);
3017             return (ERROR);
3018             }
3019         else if (IsSame ("Dollo", tkn) == SAME || IsSame ("Dollo", tkn) == CONSISTENT_WITH)
3020             {
3021             MrBayesPrint ("%s   You cannot specify more than one ordering with a single use of ctype\n", spacer, tkn);
3022             return (ERROR);
3023             }
3024         else if (IsSame ("Irreversible", tkn) == SAME || IsSame ("Irreversible", tkn) == CONSISTENT_WITH)
3025             {
3026             MrBayesPrint ("%s   You cannot specify more than one ordering with a single use of ctype\n", spacer, tkn);
3027             return (ERROR);
3028             }
3029         
3030         /* We are defining a type set in terms of another (called tkn, here). We should be able
3031            to find tkn in the list of character set names. If we cannot, then we have a problem and
3032            return an error. */
3033         if (IsSame ("All", tkn) == SAME)
3034             {
3035             for (i=0; i<numChar; i++)
3036                 tempSet[i] = 1;
3037             fromI = toJ = everyK = -1;
3038             expecting = Expecting(SEMICOLON);
3039             }
3040         else
3041             {
3042             if (numCharSets < 1)
3043                 {
3044                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
3045                 return (ERROR);
3046                 }
3047             if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
3048                 {
3049                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
3050                 return (ERROR);
3051                 }
3052                 
3053             /* add characters from charset tkn to new tempset */
3054             for (i=0; i<numChar; i++)
3055                 {
3056                 if (IsBitSet(i, charSet[index]) == YES)
3057                     tempSet[i] = 1;
3058                 }
3059             fromI = toJ = everyK = -1;
3060             expecting  = Expecting(ALPHA);
3061             expecting |= Expecting(NUMBER);
3062             expecting |= Expecting(SEMICOLON);
3063             }
3064         }
3065     else if (expecting == Expecting(NUMBER))
3066         {
3067         if (strlen(tkn) == 1 && tkn[0] == '.')
3068             tempInt = numChar;
3069         else
3070             sscanf (tkn, "%d", &tempInt);
3071         if (tempInt <= 0 || tempInt > numChar)
3072             {
3073             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
3074             return (ERROR);
3075             }
3076         tempInt--;
3077         if (foundDash == YES)
3078             {
3079             if (fromI >= 0)
3080                 toJ = tempInt;
3081             else
3082                 {
3083                 MrBayesPrint ("%s   Improperly formatted ctype\n", spacer);
3084                 return (ERROR);
3085                 }
3086             foundDash = NO;
3087             }
3088         else if (foundSlash == YES)
3089             {
3090             tempInt++;
3091             if (tempInt <= 1)
3092                 {
3093                 MrBayesPrint ("%s   Improperly formatted ctype\n", spacer);
3094                 return (ERROR);
3095                 }
3096             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
3097                 everyK = tempInt;
3098             else
3099                 {
3100                 MrBayesPrint ("%s   Improperly formatted ctype\n", spacer);
3101                 return (ERROR);
3102                 }
3103             foundSlash = NO;
3104             }
3105         else
3106             {
3107             if (fromI >= 0 && toJ < 0)
3108                 {
3109                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3110                     return (ERROR);
3111                 fromI = tempInt;
3112                 }
3113             else if (fromI < 0 && toJ < 0)
3114                 {
3115                 fromI = tempInt;
3116                 }
3117             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
3118                 {
3119                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3120                     return (ERROR);
3121                 fromI = tempInt;
3122                 toJ = everyK = -1;
3123                 }
3124             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
3125                 {
3126                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3127                     return (ERROR);
3128                 fromI = tempInt;
3129                 toJ = everyK = -1;
3130                 }
3131             else
3132                 {
3133                 MrBayesPrint ("%s   Improperly formatted ctype\n", spacer);
3134                     {
3135                     return (ERROR);
3136                     }
3137                 }
3138                 
3139             }
3140
3141         expecting  = Expecting(ALPHA);
3142         expecting |= Expecting(NUMBER);
3143         expecting |= Expecting(SEMICOLON);
3144         expecting |= Expecting(DASH);
3145         expecting |= Expecting(BACKSLASH);
3146         }
3147     else if (expecting == Expecting(DASH))
3148         {
3149         foundDash = YES;
3150         expecting = Expecting(NUMBER);
3151         }
3152     else if (expecting == Expecting(BACKSLASH))
3153         {
3154         foundSlash = YES;
3155         expecting = Expecting(NUMBER);
3156         }
3157     else
3158         return (ERROR);
3159
3160     return (NO_ERROR);
3161 }
3162
3163
3164 int DoDelete (void)
3165 {
3166     int         i, alreadyDone;
3167
3168     MrBayesPrint ("%s   Excluding taxa\n", spacer);
3169
3170     /* add set to tempSet */
3171     if (fromI >= 0 && toJ < 0)
3172         {
3173         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3174             return (ERROR);
3175         }
3176     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
3177         {
3178         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3179             return (ERROR);
3180         }
3181     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
3182         {
3183         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3184             return (ERROR);
3185         }
3186         
3187     /* merge tempSet with taxaset */
3188     alreadyDone = NO;
3189     for (i=0; i<numTaxa; i++)
3190         {
3191         if (tempSet[i] == 1)
3192             {
3193             if (taxaInfo[i].isDeleted == YES && alreadyDone == NO)
3194                 {
3195                 MrBayesPrint ("%s   Some taxa already excluded\n", spacer);
3196                 alreadyDone = YES;
3197                 }
3198             taxaInfo[i].isDeleted = YES;
3199             }
3200         }
3201
3202     SetLocalTaxa ();
3203     if (SetUpAnalysis(&globalSeed) == ERROR)
3204         return ERROR;
3205
3206     /* show tempSet (for debugging) */
3207 #   if 0
3208     for (i=0; i<numTaxa; i++)
3209         MrBayesPrint ("%4d  %4d\n", i+1, tempSet[i]);
3210 #   endif
3211
3212     return (NO_ERROR);
3213 }
3214
3215
3216 int DoDeleteParm (char *parmName, char *tkn)
3217 {
3218     int     i, index, tempInt;
3219         
3220     if (defMatrix == NO)
3221         {
3222         MrBayesPrint ("%s   A matrix must be specified before you can delete taxa\n", spacer);
3223         return (ERROR);
3224         }
3225         
3226     if (foundFirst == NO)
3227         {
3228         /* this is the first time in */
3229         fromI = toJ = everyK = -1;
3230         foundDash = NO;
3231         for (i=0; i<numTaxa; i++) /* clear tempSet */
3232             tempSet[i] = 0;
3233         foundFirst = YES;
3234         }
3235
3236     if (expecting == Expecting(ALPHA))
3237         {
3238         if (IsSame ("All", tkn) == SAME || IsSame ("All", tkn) == CONSISTENT_WITH)
3239             {
3240             for (i=0; i<numTaxa; i++)
3241                 tempSet[i] = 1;
3242             }
3243         else
3244             {
3245             if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
3246                 {
3247                 /* we are using a pre-defined taxa set */
3248                 if (numTaxaSets < 1)
3249                     {
3250                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
3251                     return (ERROR);
3252                     }
3253                 if (CheckString (taxaSetNames, numTaxaSets, tkn, &index) == ERROR)
3254                     {
3255                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
3256                     return (ERROR);
3257                     }
3258                 /* add taxa from taxset tkn to new tempSet */
3259                 for (i=0; i<numTaxa; i++)
3260                     {
3261                     if (IsBitSet (i, taxaSet[index]) == YES)
3262                         tempSet[i] = 1;
3263                     }
3264                 }
3265             else
3266                 {
3267                 /* we found the taxon name */
3268                 if (fromI >= 0 && toJ < 0)
3269                     {
3270                     if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3271                         return (ERROR);
3272                     }
3273                 else if (fromI >= 0 && toJ >= 0)
3274                     {
3275                     if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3276                         return (ERROR);
3277                     }
3278                     
3279                 tempSet[index] = 1;
3280                 }
3281             }
3282         foundDash = NO;
3283         fromI = toJ = everyK = -1;
3284         
3285         expecting  = Expecting(ALPHA);
3286         expecting |= Expecting(NUMBER);
3287         expecting |= Expecting(SEMICOLON);
3288         }
3289     else if (expecting == Expecting(NUMBER))
3290         {
3291         if (strlen(tkn) == 1 && !strcmp(tkn, "."))
3292             tempInt = numTaxa;
3293         else
3294             {
3295             sscanf (tkn, "%d", &tempInt);
3296             if (tempInt <= 0 || tempInt > numTaxa)
3297                 {
3298                 MrBayesPrint ("%s   Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa);
3299                 return (ERROR);
3300                 }
3301             }
3302         tempInt--;
3303         if (foundDash == YES)
3304             {
3305             if (fromI >= 0)
3306                 toJ = tempInt;
3307             else
3308                 {
3309                 MrBayesPrint ("%s   Improperly formatted delete set\n", spacer);
3310                 return (ERROR);
3311                 }
3312             foundDash = NO;
3313             }
3314         else
3315             {
3316             if (fromI >= 0 && toJ < 0)
3317                 {
3318                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3319                     return (ERROR);
3320                 fromI = tempInt;
3321                 }
3322             else if (fromI < 0 && toJ < 0)
3323                 {
3324                 fromI = tempInt;
3325                 }
3326             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
3327                 {
3328                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3329                     return (ERROR);
3330                 fromI = tempInt;
3331                 toJ = everyK = -1;
3332                 }
3333             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
3334                 {
3335                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3336                     return (ERROR);
3337                 fromI = tempInt;
3338                 toJ = everyK = -1;
3339                 }
3340             else
3341                 {
3342                 MrBayesPrint ("%s   Improperly formatted delete set\n", spacer);
3343                     {
3344                     return (ERROR);
3345                     }
3346                 }
3347             }
3348         expecting  = Expecting(ALPHA);
3349         expecting |= Expecting(NUMBER);
3350         expecting |= Expecting(SEMICOLON);
3351         expecting |= Expecting(DASH);
3352         }
3353     else if (expecting == Expecting(DASH))
3354         {
3355         foundDash = YES;
3356         expecting = Expecting(NUMBER);
3357         }
3358     else
3359         return (ERROR);
3360
3361     return (NO_ERROR);
3362     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
3363 }
3364
3365
3366 int DoDimensions (void)
3367 {
3368     if (inDataBlock == NO && inTaxaBlock == NO && inCharactersBlock == NO)
3369         {
3370         MrBayesPrint ("%s   Dimensions can only be defined in a data, characters or taxa block\n", spacer);
3371         return (ERROR);
3372         }
3373
3374     /* other problems are detected already when reading in DoDimensionsParm */
3375     if (inDataBlock == YES && (defTaxa == NO || defChars == NO))
3376         {
3377         MrBayesPrint ("%s   Expecting both Ntax and Nchar to be defined in a data block\n", spacer);
3378         return (ERROR);
3379         }
3380
3381     /* allocate matrix */
3382     if (inTaxaBlock == YES)
3383         {
3384         if (AllocTaxa () == ERROR)
3385             return ERROR;
3386         MrBayesPrint ("%s   Defining new set of %d taxa\n", spacer, numTaxa);
3387         }
3388
3389     if (inCharactersBlock == YES)
3390         {
3391         if (AllocMatrix() == ERROR)
3392             return (ERROR);
3393         MrBayesPrint ("%s   Defining new character matrix with %d characters\n", spacer, numChar);
3394         }
3395
3396     if (inDataBlock == YES)
3397         {
3398         if (AllocMatrix() == ERROR)
3399             return (ERROR);
3400         MrBayesPrint ("%s   Defining new matrix with %d taxa and %d characters\n", spacer, numTaxa, numChar);
3401         }
3402
3403     return (NO_ERROR);
3404 }
3405
3406
3407 int DoDimensionsParm (char *parmName, char *tkn)
3408 {
3409     if (expecting == Expecting(PARAMETER))
3410         {
3411         expecting = Expecting(EQUALSIGN);
3412         }
3413     else
3414         {
3415         /* set Ntax (numTaxa) *****************************************************************/
3416         if (!strcmp(parmName, "Ntax"))
3417             {
3418             if (inCharactersBlock == YES)
3419                 {
3420                 MrBayesPrint ("%s   You cannot define ntax in a characters block\n");
3421                 return (ERROR);
3422                 }
3423             if (expecting == Expecting(EQUALSIGN))
3424                 expecting = Expecting(NUMBER);
3425             else if (expecting == Expecting(NUMBER))
3426                 {
3427                 sscanf (tkn, "%d", &numTaxa);
3428                 defTaxa = YES;
3429                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3430                 }
3431             else
3432                 return (ERROR);
3433             }
3434         /* set Nchar (numChar) ****************************************************************/
3435         else if (!strcmp(parmName, "Nchar"))
3436             {
3437             if (inTaxaBlock == YES)
3438                 {
3439                 MrBayesPrint ("%s   You cannot define nchar in a taxa block\n");
3440                 return (ERROR);
3441                 }
3442             if (expecting == Expecting(EQUALSIGN))
3443                 expecting = Expecting(NUMBER);
3444             else if (expecting == Expecting(NUMBER))
3445                 {
3446                 sscanf (tkn, "%d", &numChar);
3447                 defChars = YES;
3448                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3449                 }
3450             else
3451                 return (ERROR);
3452             }
3453         else
3454             return (ERROR);
3455         }
3456
3457     return (NO_ERROR);
3458 }
3459
3460
3461 int DoDisclaimer (void)
3462 {
3463     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
3464     MrBayesPrint ("   Disclaimer                                                                    \n");
3465     MrBayesPrint ("                                                                                 \n");
3466     MrBayesPrint ("   Copyright 2003 by John P. Huelsenbeck and Fredrik Ronquist                    \n");
3467     MrBayesPrint ("                                                                                 \n");
3468     MrBayesPrint ("   This software package is provided \"as is\" and without a warranty of any     \n");
3469     MrBayesPrint ("   kind. In no event shall the authors be held responsible for any damage        \n");
3470     MrBayesPrint ("   resulting from the use of this software. The program--including source code,  \n");
3471     MrBayesPrint ("   example data sets, and executables--is distributed free of charge for         \n");
3472     MrBayesPrint ("   academic use only.                                                            \n");
3473     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
3474
3475     return (NO_ERROR);
3476 }
3477
3478
3479 int DoEndBlock (void)
3480 {
3481     if (inMrbayesBlock == YES)
3482         {
3483         MrBayesPrint ("   Exiting mrbayes block\n");
3484         inMrbayesBlock = NO;
3485         }
3486     else if (inDataBlock == YES)
3487         {
3488         MrBayesPrint ("   Exiting data block\n");
3489         inDataBlock = NO;
3490         }
3491     else if (inCharactersBlock == YES)
3492         {
3493         MrBayesPrint ("   Exiting characters block\n");
3494         inCharactersBlock = NO;
3495         }
3496     else if (inTaxaBlock == YES)
3497         {
3498         MrBayesPrint ("   Exiting taxa block\n");
3499         if (numNamedTaxa < numTaxa)
3500             {
3501             MrBayesPrint ("%s   Leaving taxa block without taxon labels being defined\n", spacer);
3502             FreeTaxa();
3503             }
3504         inTaxaBlock = NO;
3505         }
3506     else if (inTreesBlock == YES)
3507         {
3508         MrBayesPrint ("   Exiting trees block\n");
3509         inTreesBlock = NO;
3510         ResetTranslateTable();
3511         }
3512     else if (inForeignBlock == YES)
3513         {
3514         MrBayesPrint ("   Exiting foreign block\n");
3515         inForeignBlock = NO;
3516         }
3517     else
3518         {
3519         MrBayesPrint ("   Unknown \"end\" statement\n");
3520         return (ERROR);
3521         }
3522
3523     strcpy(spacer,"");  /* reset indentation */
3524     return (NO_ERROR);
3525 }
3526
3527
3528 int DoExecute (void)
3529 {
3530     int         c, i, rc, cmdLine, lineTerm, longestLineLength, nErrors;
3531     char        *s, exeFileName[100];
3532     FILE        *fp;
3533     CmdType     *oldCommandPtr;
3534 #   if defined (MPI_ENABLED)
3535     int         sumErrors;
3536 #   endif
3537         
3538     nErrors = 0;
3539     cmdLine = 0;
3540     numOpenExeFiles++;
3541     s = NULL;
3542     strncpy (exeFileName, inputFileName, 98);
3543     
3544     if (numOpenExeFiles > 1)
3545         MrBayesPrint ("\n%s   Executing file \"%s\"...\n\n", spacer, inputFileName);
3546     else
3547         MrBayesPrint ("%s   Executing file \"%s\"\n", spacer, inputFileName);
3548
3549     /* Save old command ptr */
3550     oldCommandPtr = commandPtr;
3551
3552     /* open binary file */
3553     if ((fp = OpenBinaryFileR(inputFileName)) == NULL)
3554         nErrors++;
3555
3556     /* set indentation to 0 */
3557     strcpy (spacer, "");
3558     
3559 #   if defined (MPI_ENABLED)
3560     MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3561     if (sumErrors > 0)
3562         {
3563         MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3564         goto errorExit;
3565         }
3566 #   else
3567     if (nErrors > 0)
3568         goto errorExit;
3569 #   endif
3570
3571     /* find out what type of line termination is used */
3572     lineTerm = LineTermType (fp);
3573     if (lineTerm == LINETERM_MAC)
3574         MrBayesPrint ("%s   Macintosh line termination\n", spacer);
3575     else if (lineTerm == LINETERM_DOS)
3576         MrBayesPrint ("%s   DOS line termination\n", spacer);
3577     else if (lineTerm == LINETERM_UNIX)
3578         MrBayesPrint ("%s   UNIX line termination\n", spacer);
3579     else
3580         {
3581         MrBayesPrint ("%s   Unknown line termination\n", spacer);
3582         nErrors++;
3583         }
3584 #   if defined (MPI_ENABLED)
3585     MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3586     if (sumErrors > 0)
3587         {
3588         MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3589         goto errorExit;
3590         }
3591 #   else
3592     if (nErrors > 0)
3593         goto errorExit;
3594 #   endif
3595             
3596     /* find length of longest line */
3597     longestLineLength = LongestLine (fp);
3598     MrBayesPrint ("%s   Longest line length = %d\n", spacer, longestLineLength);
3599     longestLineLength += 50;
3600     
3601     /* check that longest line is not longer than CMD_STRING_LENGTH */
3602     if (longestLineLength >= CMD_STRING_LENGTH - 100)
3603         {
3604         /*MrBayesPrint ("%s   A maximum of %d characters is allowed on a single line\n", spacer, CMD_STRING_LENGTH - 100);*/
3605         MrBayesPrint ("%s   The longest line of the file %s\n", spacer, inputFileName);
3606         MrBayesPrint ("%s   contains at least one line with %d characters.\n", spacer, longestLineLength);
3607         }
3608     /*
3609 #   if defined (MPI_ENABLED)
3610     MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3611     if (sumErrors > 0)
3612         {
3613         MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3614         goto errorExit;
3615         }
3616 #   else
3617     if (nErrors > 0)
3618         goto errorExit;
3619 #   endif
3620     */
3621
3622     /* allocate a string long enough to hold a line */
3623     s = (char *)SafeMalloc((size_t)longestLineLength * sizeof(char));
3624     if (!s)
3625         {
3626         MrBayesPrint ("%s   Problem allocating string for reading file\n", spacer);
3627         nErrors++;
3628         }
3629 #   if defined (MPI_ENABLED)
3630     MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3631     if (sumErrors > 0)
3632         {
3633         MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3634         goto errorExit;
3635         }
3636 #   else
3637     if (nErrors > 0)
3638         goto errorExit;
3639 #   endif
3640
3641     /* close binary file */
3642     SafeFclose (&fp);
3643     
3644     /* open text file */
3645     if ((fp = OpenTextFileR(inputFileName)) == NULL)
3646         {
3647         nErrors++;
3648         }
3649 #   if defined (MPI_ENABLED)
3650     MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3651     if (sumErrors > 0)
3652         {
3653         MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3654         goto errorExit;
3655         }
3656 #   else
3657     if (nErrors > 0)
3658         goto errorExit;
3659 #   endif
3660     
3661     /* parse file, reading each line in turn */
3662     MrBayesPrint ("%s   Parsing file\n", spacer);
3663
3664     inMrbayesBlock = inDataBlock = inForeignBlock = inTreesBlock = NO;
3665     foundNewLine = NO;
3666     expecting = Expecting(COMMAND);
3667     cmdLine = 0;
3668
3669     do {
3670         /* read in a new line into s */
3671         i = 0;
3672         do {
3673             c = fgetc(fp);
3674             if (c == '\r' || c == '\n' || c == EOF)
3675                 s[i++] = '\n';
3676             else
3677                 s[i++] = c;
3678             } while (s[i-1] != '\n');
3679         s[i] = '\0';
3680         foundNewLine = YES;
3681         cmdLine++;
3682
3683         /* process string if not empty */
3684         if (strlen(s) > 1)
3685             {
3686             /* check that all characters in the string are valid */
3687             if (CheckStringValidity (s) == ERROR)
3688                 {
3689                 nErrors++;
3690                 }
3691 #           if defined (MPI_ENABLED)
3692             MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3693             if (sumErrors > 0)
3694                 {
3695                 MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3696                 goto errorExit;
3697                 }
3698 #           else
3699             if (nErrors > 0)
3700                 goto errorExit;
3701 #           endif
3702                 
3703             /* interpret commands on line */
3704             rc = ParseCommand (s);
3705             if (rc == ERROR)
3706                 nErrors++;
3707 #           if defined (MPI_ENABLED)
3708             MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3709             if (sumErrors > 0)
3710                 {
3711                 MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3712                 goto errorExit;
3713                 }
3714 #           else
3715             if (nErrors > 0)
3716                 goto errorExit;
3717 #           endif
3718             if (rc == NO_ERROR_QUIT)
3719                 nErrors++;
3720 #           if defined (MPI_ENABLED)
3721             MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3722             if (sumErrors > 0)
3723                 goto quitExit;
3724 #           else
3725             if (nErrors > 0)
3726                 goto quitExit;
3727 #           endif
3728             }
3729         } while (c != EOF); 
3730     
3731     MrBayesPrint ("%s   Reached end of file\n", spacer);
3732
3733     if (inComment == YES)
3734         nErrors++;
3735
3736 #   if defined (MPI_ENABLED)
3737     MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
3738     if (sumErrors > 0)
3739         {
3740         MrBayesPrint ("%s   There was an error on at least one processor\n", spacer);
3741         goto errorExit;
3742         }
3743 #   else
3744     if (nErrors > 0)
3745         goto errorExit;
3746 #   endif
3747
3748     if (s)
3749         free (s);
3750     SafeFclose (&fp);
3751     numOpenExeFiles--;
3752
3753     if (numOpenExeFiles > 0)
3754         {
3755         inMrbayesBlock = YES;
3756         MrBayesPrint ("\n   Returning execution to calling file ...\n\n");
3757         strcpy (spacer, "   ");
3758         }
3759     else
3760         strcpy (spacer, "");
3761
3762     commandPtr = oldCommandPtr;
3763
3764     return (NO_ERROR);
3765     
3766     quitExit:
3767         if (s)
3768             free (s);
3769         SafeFclose (&fp);
3770         numOpenExeFiles--;
3771         if (numOpenExeFiles > 0)
3772             {
3773             inMrbayesBlock = YES;
3774             strcpy (spacer, "   ");
3775             }
3776         else
3777             strcpy (spacer, "");
3778
3779         commandPtr = oldCommandPtr;
3780
3781         return (NO_ERROR_QUIT);
3782             
3783     errorExit:
3784         if (inComment == YES)
3785             {
3786             MrBayesPrint ("%s   ERROR: Reached end of file while in comment.\n", spacer);
3787             inComment = NO;
3788             numComments = 0;
3789             }
3790         if (fp)
3791             {
3792             MrBayesPrint ("%s   The error occurred when reading char. %d on line %d\n", spacer, tokenP-cmdStr-strlen(token)+1, cmdLine);
3793             MrBayesPrint ("%s      in the file '%s'\n", spacer, exeFileName);
3794             }
3795         if (s)
3796             free (s);
3797         SafeFclose (&fp);
3798         numOpenExeFiles--;  /* we increase the value above even if no file is successfully opened */
3799
3800         /* make sure we exit the block we were reading from correctly */
3801         if (inMrbayesBlock == YES)
3802             inMrbayesBlock = NO;
3803         else if (inDataBlock == YES)
3804             inDataBlock = NO;
3805         else if (inTreesBlock == YES)
3806             {
3807             inTreesBlock = NO;
3808             ResetTranslateTable();
3809             }
3810         else if (inForeignBlock == YES)
3811             inForeignBlock = NO;
3812
3813         /* make sure correct return if we came from mrbayes block in another execute file */
3814         if (numOpenExeFiles > 0)
3815             {
3816             inMrbayesBlock = YES;
3817             MrBayesPrint ("\n   Returning execution to calling file ...\n\n");
3818             strcpy (spacer, "   ");
3819             commandPtr = oldCommandPtr;
3820             return (ERROR);
3821             }
3822         else
3823             strcpy (spacer, "");
3824
3825         commandPtr = oldCommandPtr;
3826
3827         return (ERROR);
3828 }
3829
3830
3831 int DoExecuteParm (char *parmName, char *tkn)
3832 {
3833     if (strlen(tkn)>99)
3834         {
3835         MrBayesPrint ("%s   Maximum allowed length of file name is 99 characters. The given name:\n", spacer);
3836         MrBayesPrint ("%s      '%s'\n", spacer,tkn);
3837         MrBayesPrint ("%s   has %d characters.\n", spacer,strlen(tkn));
3838         return (ERROR);
3839         }
3840     strcpy (inputFileName, tkn);
3841     
3842     expecting = Expecting (SEMICOLON);
3843
3844     return (NO_ERROR);
3845     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
3846 }
3847
3848
3849 int DoExclude (void)
3850 {
3851     int         i, alreadyDone;
3852
3853     MrBayesPrint ("%s   Excluding character(s)\n", spacer);
3854
3855     /* add set to tempSet */
3856     if (fromI >= 0 && toJ < 0)
3857         {
3858         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3859             return (ERROR);
3860         }
3861     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
3862         {
3863         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3864             return (ERROR);
3865         }
3866     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
3867         {
3868         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
3869             return (ERROR);
3870         }
3871         
3872     /* merge tempSet with charset */
3873     alreadyDone = NO;
3874     for (i=0; i<numChar; i++)
3875         {
3876         if (tempSet[i] == 1)
3877             {
3878             if (charInfo[i].isExcluded == YES && alreadyDone == NO)
3879                 {
3880                 MrBayesPrint ("%s   Some characters already excluded\n", spacer);
3881                 alreadyDone = YES;
3882                 }
3883             charInfo[i].isExcluded = YES;
3884             }
3885         }
3886         
3887     foundFirst = NO;
3888
3889     /* reset analysis to recompress data */
3890     if (SetUpAnalysis(&globalSeed) == ERROR)
3891         return ERROR;
3892
3893     return (NO_ERROR);
3894 }
3895
3896
3897 int DoExcludeParm (char *parmName, char *tkn)
3898 {
3899     int     i, index, tempInt;
3900         
3901     if (defMatrix == NO)
3902         {
3903         MrBayesPrint ("%s   A matrix must be specified before you can exclude characters\n", spacer);
3904         return (ERROR);
3905         }
3906         
3907     if (foundFirst == NO)
3908         {
3909         /* this is the first time in */
3910         fromI = toJ = everyK = -1;
3911         foundDash = foundSlash = NO;
3912         for (i=0; i<numChar; i++) /* clear tempSet */
3913             tempSet[i] = 0;
3914         foundFirst = YES;
3915         }
3916
3917     if (expecting == Expecting(ALPHA))
3918         {
3919         if (IsSame ("All", tkn) == SAME || IsSame ("All", tkn) == CONSISTENT_WITH)
3920             {
3921             for (i=0; i<numChar; i++)
3922                 tempSet[i] = 1;
3923             }
3924         else if (IsSame ("Missambig", tkn) == SAME || IsSame ("Missambig", tkn) == CONSISTENT_WITH)
3925             {
3926             for (i=0; i<numChar; i++)
3927                 {
3928                 if (charInfo[i].isMissAmbig == YES)
3929                     tempSet[i] = 1;
3930                 }
3931             }
3932         else
3933             {
3934             /* we are using a pre-defined character set */
3935             if (numCharSets < 1)
3936                 {
3937                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
3938                 return (ERROR);
3939                 }
3940             if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
3941                 {
3942                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
3943                 return (ERROR);
3944                 }
3945             /* add characters from charset tkn to new tempSet */
3946             for (i=0; i<numChar; i++)
3947                 {
3948                 if (IsBitSet(i, charSet[index]) == YES)
3949                     tempSet[i] = 1;
3950                 }
3951             fromI = toJ = everyK = -1;
3952             }
3953
3954         expecting  = Expecting(ALPHA);
3955         expecting |= Expecting(NUMBER);
3956         expecting |= Expecting(SEMICOLON);
3957         }
3958     else if (expecting == Expecting(NUMBER))
3959         {
3960         if (strlen(tkn) == 1 && tkn[0] == '.')
3961             tempInt = numChar;
3962         else
3963             sscanf (tkn, "%d", &tempInt);
3964         if (tempInt <= 0 || tempInt > numChar)
3965             {
3966             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
3967             return (ERROR);
3968             }
3969         tempInt--;
3970         if (foundDash == YES)
3971             {
3972             if (fromI >= 0)
3973                 toJ = tempInt;
3974             else
3975                 {
3976                 MrBayesPrint ("%s   Improperly formatted exclude set\n", spacer);
3977                 return (ERROR);
3978                 }
3979             foundDash = NO;
3980             }
3981         else if (foundSlash == YES)
3982             {
3983             tempInt++;
3984             if (tempInt <= 1)
3985                 {
3986                 MrBayesPrint ("%s   Improperly formatted exclude set\n", spacer);
3987                 return (ERROR);
3988                 }
3989             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
3990                 everyK = tempInt;
3991             else
3992                 {
3993                 MrBayesPrint ("%s   Improperly formatted exclude set\n", spacer);
3994                 return (ERROR);
3995                 }
3996             foundSlash = NO;
3997             }
3998         else
3999             {
4000             if (fromI >= 0 && toJ < 0)
4001                 {
4002                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4003                     return (ERROR);
4004                 fromI = tempInt;
4005                 }
4006             else if (fromI < 0 && toJ < 0)
4007                 {
4008                 fromI = tempInt;
4009                 }
4010             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4011                 {
4012                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4013                     return (ERROR);
4014                 fromI = tempInt;
4015                 toJ = everyK = -1;
4016                 }
4017             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4018                 {
4019                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4020                     return (ERROR);
4021                 fromI = tempInt;
4022                 toJ = everyK = -1;
4023                 }
4024             else
4025                 {
4026                 MrBayesPrint ("%s   Improperly formatted exclude set\n", spacer);
4027                     {
4028                     return (ERROR);
4029                     }
4030                 }
4031             }
4032         expecting  = Expecting(ALPHA);
4033         expecting |= Expecting(NUMBER);
4034         expecting |= Expecting(SEMICOLON);
4035         expecting |= Expecting(DASH);
4036         expecting |= Expecting(BACKSLASH);
4037         }
4038     else if (expecting == Expecting(DASH))
4039         {
4040         foundDash = YES;
4041         expecting = Expecting(NUMBER);
4042         }
4043     else if (expecting == Expecting(BACKSLASH))
4044         {
4045         foundSlash = YES;
4046         expecting = Expecting(NUMBER);
4047         }
4048     else
4049         return (ERROR);
4050
4051     return (NO_ERROR);
4052     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
4053 }
4054
4055
4056 int DoFormat (void)
4057 {
4058     if (inDataBlock == NO && inCharactersBlock == NO)
4059         {
4060         MrBayesPrint ("%s   Formats can only be defined in a data or characters block\n", spacer);
4061         return (ERROR);
4062         }
4063
4064     return CheckInitialPartitions();
4065 }
4066
4067
4068 int DoFormatParm (char *parmName, char *tkn)
4069 {
4070     int         i, tempInt;
4071     char        tempStr[100];
4072     
4073     if (inDataBlock == NO && inCharactersBlock == NO)
4074         {
4075         MrBayesPrint ("%s   Formats can only be defined in a data or characters block\n", spacer);
4076         return (ERROR);
4077         }
4078     if (defTaxa == NO || defChars == NO)
4079         {
4080         MrBayesPrint ("%s   The dimensions of the matrix must be defined before the format\n", spacer);
4081         return (ERROR);
4082         }
4083     
4084     if (expecting == Expecting(PARAMETER))
4085         {
4086         expecting = Expecting(EQUALSIGN);
4087         if (!strcmp(parmName, "Interleave"))
4088             {
4089             expecting = Expecting(EQUALSIGN) | Expecting(PARAMETER) | Expecting(SEMICOLON);
4090             isInterleaved = YES;
4091             }
4092         }
4093     else
4094         {
4095         /* set Datatype (dataType) ************************************************************/
4096         if (!strcmp(parmName, "Datatype"))
4097             {
4098             if (expecting == Expecting(EQUALSIGN))
4099                 expecting = Expecting(ALPHA);
4100             else if (expecting == Expecting(ALPHA))
4101                 {
4102                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
4103                     {
4104                     if (isMixed == NO)
4105                         {
4106                         if (!strcmp(tempStr, "Dna"))
4107                             dataType = DNA;
4108                         else if (!strcmp(tempStr, "Rna"))
4109                             dataType = RNA;
4110                         else if (!strcmp(tempStr, "Protein"))
4111                             dataType = PROTEIN;
4112                         else if (!strcmp(tempStr, "Restriction"))
4113                             dataType = RESTRICTION;
4114                         else if (!strcmp(tempStr, "Standard"))
4115                             dataType = STANDARD;
4116                         else if (!strcmp(tempStr, "Continuous"))
4117                             dataType = CONTINUOUS;
4118                         else if (!strcmp(tempStr, "Mixed"))
4119                             {
4120                             dataType = MIXED;
4121                             isMixed = YES;
4122                             for (i=0; i<numChar; i++)
4123                                 tempSet[i] = 0;
4124                             fromI = toJ = everyK = -1;
4125                             foundDash = foundSlash = NO;
4126                             numDivisions = 0;
4127                             MrBayesPrint ("%s   Data is Mixed\n", spacer);
4128                             }
4129                         if (dataType == MIXED)
4130                             expecting = Expecting(LEFTPAR);
4131                         else
4132                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4133                         }
4134                     else
4135                         {
4136                         if (!strcmp(tempStr, "Dna"))
4137                             dataType = DNA;
4138                         else if (!strcmp(tempStr, "Rna"))
4139                             dataType = RNA;
4140                         else if (!strcmp(tempStr, "Protein"))
4141                             dataType = PROTEIN;
4142                         else if (!strcmp(tempStr, "Restriction"))
4143                             dataType = RESTRICTION;
4144                         else if (!strcmp(tempStr, "Standard"))
4145                             dataType = STANDARD;
4146                         else if (!strcmp(tempStr, "Continuous"))
4147                             dataType = CONTINUOUS;
4148                         else if (!strcmp(tempStr, "Mixed"))
4149                             {
4150                             MrBayesPrint ("%s   Cannot have mixed datatype within a mixed datatype\n", spacer);
4151                             return (ERROR);
4152                             }
4153                         expecting = Expecting(COLON);
4154                         for (i=0; i<numChar; i++)
4155                             tempSet[i] = 0;
4156                         fromI = toJ = everyK = -1;
4157                         foundDash = foundSlash = NO;
4158                         }
4159                     if (isMixed == NO)
4160                         {
4161                         numDivisions = 1;
4162                         for (i=0; i<numChar; i++)
4163                             {
4164                             charInfo[i].charType = dataType;
4165                             partitionId[i][0] = numDivisions;
4166                             }
4167                         }
4168                     }
4169                 else
4170                     {
4171                     MrBayesPrint ("%s   Invalid data type argument\n", spacer);
4172                     return (ERROR);
4173                     }
4174                 if (isMixed == NO)
4175                     MrBayesPrint ("%s   Data is %s\n", spacer, tempStr);
4176                 else if (strcmp(tempStr, "Mixed"))
4177                     MrBayesPrint ("%s      Data for partition %d is %s\n", spacer, numDivisions+1, tempStr);
4178                 }
4179             else if (expecting == Expecting(LEFTPAR))
4180                 {
4181                 expecting = Expecting(ALPHA);
4182                 }
4183             else if (expecting == Expecting(COLON))
4184                 {
4185                 expecting = Expecting(NUMBER);
4186                 }
4187             else if (expecting == Expecting(NUMBER))
4188                 {
4189                 if (strlen(tkn) == 1 && tkn[0] == '.')
4190                     tempInt = numChar;
4191                 else
4192                     sscanf (tkn, "%d", &tempInt);
4193                 if (tempInt <= 0 || tempInt > numChar)
4194                     {
4195                     MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
4196                     return (ERROR);
4197                     }
4198                 tempInt--;
4199                 if (foundDash == YES)
4200                     {
4201                     if (fromI >= 0)
4202                         toJ = tempInt;
4203                     else
4204                         {
4205                         MrBayesPrint ("%s   Improperly formatted partition\n", spacer);
4206                         return (ERROR);
4207                         }
4208                     foundDash = NO;
4209                     }
4210                 else if (foundSlash == YES)
4211                     {
4212                     tempInt++;
4213                     if (tempInt <= 1)
4214                         {
4215                         MrBayesPrint ("%s   Improperly formatted partition\n", spacer);
4216                         return (ERROR);
4217                         }
4218                     if (fromI >= 0 && toJ >= 0 && fromI < toJ)
4219                         everyK = tempInt;
4220                     else
4221                         {
4222                         MrBayesPrint ("%s   Improperly formatted partition\n", spacer);
4223                         return (ERROR);
4224                         }
4225                     foundSlash = NO;
4226                     }
4227                 else
4228                     {
4229                     if (fromI >= 0 && toJ < 0)
4230                         {
4231                         if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4232                             return (ERROR);
4233                         fromI = tempInt;
4234                         }
4235                     else if (fromI < 0 && toJ < 0)
4236                         {
4237                         fromI = tempInt;
4238                         }
4239                     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4240                         {
4241                         if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4242                             return (ERROR);
4243                         fromI = tempInt;
4244                         toJ = everyK = -1;
4245                         }
4246                     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4247                         {
4248                         if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4249                             return (ERROR);
4250                         fromI = tempInt;
4251                         toJ = everyK = -1;
4252                         }
4253                     else
4254                         {
4255                         MrBayesPrint ("%s   Improperly formatted partition\n", spacer);
4256                             {
4257                             return (ERROR);
4258                             }
4259                         }
4260                         
4261                     }
4262                 expecting  = Expecting(NUMBER);
4263                 expecting |= Expecting(DASH);
4264                 expecting |= Expecting(BACKSLASH);
4265                 expecting |= Expecting(COMMA);
4266                 expecting |= Expecting(RIGHTPAR);
4267                 }
4268             else if (expecting == Expecting(DASH))
4269                 {
4270                 foundDash = YES;
4271                 expecting = Expecting(NUMBER);
4272                 }
4273             else if (expecting == Expecting(BACKSLASH))
4274                 {
4275                 foundSlash = YES;
4276                 expecting = Expecting(NUMBER);
4277                 }
4278             else if (expecting == Expecting(COMMA))
4279                 {
4280                 /* add set to tempSet */
4281                 if (fromI >= 0 && toJ < 0)
4282                     {
4283                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4284                         return (ERROR);
4285                     }
4286                 else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4287                     {
4288                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4289                         return (ERROR);
4290                     }
4291                 else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4292                     {
4293                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4294                         return (ERROR);
4295                     }
4296                 for (i=0; i<numChar; i++)
4297                     {
4298                     if (tempSet[i] == numDivisions)
4299                         charInfo[i].charType = dataType;
4300                     }
4301
4302                 /* merge tempSet */
4303                 for (i=0; i<numChar; i++)
4304                     {
4305                     if (tempSet[i] != 0)
4306                         {
4307                         if (partitionId[i][0] == 0)
4308                             {
4309                             charInfo[i].charType = dataType;
4310                             partitionId[i][0] = numDivisions + 1;
4311                             }
4312                         else
4313                             {
4314                             MrBayesPrint ("%s   Improperly formatted partition (same character found in multiple partitions)\n", spacer);
4315                             return (ERROR);
4316                             }
4317                         }
4318                     }
4319                 
4320                 /* increment number of partitions */
4321                 numDivisions++;             
4322                 expecting = Expecting(ALPHA);
4323                 }
4324             else if (expecting == Expecting(RIGHTPAR))
4325                 {
4326                 /* add set to tempSet */
4327                 if (fromI >= 0 && toJ < 0)
4328                     {
4329                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4330                         return (ERROR);
4331                     }
4332                 else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4333                     {
4334                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4335                         return (ERROR);
4336                     }
4337                 else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4338                     {
4339                     if (AddToSet (fromI, toJ, everyK, numDivisions+1) == ERROR)
4340                         return (ERROR);
4341                     }
4342                     
4343                 /* merge tempSet */
4344                 for (i=0; i<numChar; i++)
4345                     {
4346                     if (tempSet[i] != 0)
4347                         {
4348                         if (partitionId[i][0] == 0)
4349                             {
4350                             charInfo[i].charType = dataType;
4351                             partitionId[i][0] = numDivisions + 1;
4352                             }
4353                         else
4354                             {
4355                             MrBayesPrint ("%s   Improperly formatted partition (same character found in multiple partitions)\n", spacer);
4356                             return (ERROR);
4357                             }
4358                         }
4359                     }
4360                 
4361                 /* increment number of partitions */
4362                 numDivisions++;             
4363                 if (isMixed == YES)
4364                     dataType = MIXED;
4365                     
4366                 if (numDivisions > 1)
4367                     MrBayesPrint ("%s   There are a total of %d default data divisions\n", spacer, numDivisions);
4368                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4369                 }
4370             else
4371                 return (ERROR);
4372             }
4373         /* set Interleave (isInterleaved) *****************************************************/
4374         else if (!strcmp(parmName, "Interleave"))
4375             {
4376             if (expecting == Expecting(EQUALSIGN))
4377                 expecting = Expecting(ALPHA);
4378             else if (expecting == Expecting(ALPHA))
4379                 {
4380                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
4381                     {
4382                     if (!strcmp(tempStr, "Yes"))
4383                         isInterleaved = YES;
4384                     else
4385                         isInterleaved = NO;
4386                     }
4387                 else
4388                     {
4389                     MrBayesPrint ("%s   Invalid argument for interleaved data\n", spacer);
4390                     return (ERROR);
4391                     }
4392                 if (isInterleaved == YES)
4393                     MrBayesPrint ("%s   Data matrix is interleaved\n", spacer);
4394                 else
4395                     MrBayesPrint ("%s   Data matrix is not interleaved\n", spacer);
4396                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4397                 }
4398             else
4399                 return (ERROR);
4400             }
4401         /* set Gap (gapId) ********************************************************************/
4402         else if (!strcmp(parmName, "Gap"))
4403             {
4404             if (expecting == Expecting(EQUALSIGN))
4405                 {
4406                 expecting  = Expecting(ALPHA);
4407                 expecting |= Expecting(QUESTIONMARK);
4408                 expecting |= Expecting(DASH);
4409                 expecting |= Expecting(NUMBER);
4410                 expecting |= Expecting(ASTERISK);
4411                 expecting |= Expecting(EXCLAMATIONMARK);
4412                 expecting |= Expecting(PERCENT);
4413                 expecting |= Expecting(WEIRD);
4414                 expecting |= Expecting(VERTICALBAR);
4415                 }
4416             else if (((expecting & Expecting(ALPHA)) == Expecting(ALPHA)) || 
4417                      ((expecting & Expecting(QUESTIONMARK)) == Expecting(QUESTIONMARK)) || 
4418                      ((expecting & Expecting(DASH)) == Expecting(DASH)) || 
4419                      ((expecting & Expecting(NUMBER)) == Expecting(NUMBER)) || 
4420                      ((expecting & Expecting(ASTERISK)) == Expecting(ASTERISK)) || 
4421                      ((expecting & Expecting(EXCLAMATIONMARK)) == Expecting(EXCLAMATIONMARK)) || 
4422                      ((expecting & Expecting(PERCENT)) == Expecting(PERCENT)) || 
4423                      ((expecting & Expecting(WEIRD)) == Expecting(WEIRD)) ||
4424                      ((expecting & Expecting(VERTICALBAR)) == Expecting(VERTICALBAR)))
4425                 {
4426                 if (strlen(tkn) == 1)
4427                     {
4428                     if (tkn[0] == matchId || tkn[0] == missingId)
4429                         {
4430                         MrBayesPrint ("%s   Gap character matches matching or missing characters\n", spacer);
4431                         return (ERROR);
4432                         }
4433                     gapId = tkn[0];
4434                     }
4435                 else
4436                     {
4437                     MrBayesPrint ("%s   Invalid gap argument %s\n", spacer, tkn);
4438                     return (ERROR);
4439                     }
4440                 MrBayesPrint ("%s   Gaps coded as %s\n", spacer, tkn);
4441                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4442                 }
4443             else
4444                 return (ERROR);
4445             }
4446         /* set Missing (missingId) ************************************************************/
4447         else if (!strcmp(parmName, "Missing"))
4448             {
4449             if (expecting == Expecting(EQUALSIGN))
4450                 {
4451                 expecting  = Expecting(ALPHA);
4452                 expecting |= Expecting(QUESTIONMARK);
4453                 expecting |= Expecting(DASH);
4454                 expecting |= Expecting(NUMBER);
4455                 expecting |= Expecting(ASTERISK);
4456                 expecting |= Expecting(EXCLAMATIONMARK);
4457                 expecting |= Expecting(PERCENT);
4458                 expecting |= Expecting(WEIRD);
4459                 expecting |= Expecting(VERTICALBAR);
4460                 }
4461             else if (((expecting & Expecting(ALPHA)) == Expecting(ALPHA)) || 
4462                      ((expecting & Expecting(QUESTIONMARK)) == Expecting(QUESTIONMARK)) || 
4463                      ((expecting & Expecting(DASH)) == Expecting(DASH)) || 
4464                      ((expecting & Expecting(NUMBER)) == Expecting(NUMBER)) || 
4465                      ((expecting & Expecting(ASTERISK)) == Expecting(ASTERISK)) || 
4466                      ((expecting & Expecting(EXCLAMATIONMARK)) == Expecting(EXCLAMATIONMARK)) || 
4467                      ((expecting & Expecting(PERCENT)) == Expecting(PERCENT)) || 
4468                      ((expecting & Expecting(WEIRD)) == Expecting(WEIRD)) ||
4469                      ((expecting & Expecting(VERTICALBAR)) == Expecting(VERTICALBAR)))
4470                 {
4471                 if (strlen(tkn) == 1)
4472                     {
4473                     if (tkn[0] == gapId || tkn[0] == matchId)
4474                         {
4475                         MrBayesPrint ("%s   Missing character matches matching or gap characters\n", spacer);
4476                         return (ERROR);
4477                         }
4478                     missingId = tkn[0];
4479                     }
4480                 else
4481                     {
4482                     MrBayesPrint ("%s   Invalid missing argument %s\n", spacer, tkn);
4483                     return (ERROR);
4484                     }
4485                 MrBayesPrint ("%s   Missing data coded as %s\n", spacer, tkn);
4486                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4487                 }
4488             else
4489                 return (ERROR);
4490             }
4491         /* set Matchchar (matchId) ************************************************************/
4492         else if (!strcmp(parmName, "Matchchar"))
4493             {
4494             if (expecting == Expecting(EQUALSIGN))
4495                 {
4496                 expecting  = Expecting(ALPHA);
4497                 expecting |= Expecting(QUESTIONMARK);
4498                 expecting |= Expecting(DASH);
4499                 expecting |= Expecting(NUMBER);
4500                 expecting |= Expecting(ASTERISK);
4501                 expecting |= Expecting(EXCLAMATIONMARK);
4502                 expecting |= Expecting(PERCENT);
4503                 expecting |= Expecting(WEIRD);
4504                 expecting |= Expecting(VERTICALBAR);
4505                 }
4506             else if (((expecting & Expecting(ALPHA)) == Expecting(ALPHA)) || 
4507                      ((expecting & Expecting(QUESTIONMARK)) == Expecting(QUESTIONMARK)) || 
4508                      ((expecting & Expecting(DASH)) == Expecting(DASH)) || 
4509                      ((expecting & Expecting(NUMBER)) == Expecting(NUMBER)) || 
4510                      ((expecting & Expecting(ASTERISK)) == Expecting(ASTERISK)) || 
4511                      ((expecting & Expecting(EXCLAMATIONMARK)) == Expecting(EXCLAMATIONMARK)) || 
4512                      ((expecting & Expecting(PERCENT)) == Expecting(PERCENT)) || 
4513                      ((expecting & Expecting(WEIRD)) == Expecting(WEIRD)) ||
4514                      ((expecting & Expecting(VERTICALBAR)) == Expecting(VERTICALBAR)))
4515                 {
4516                 if (strlen(tkn) == 1)
4517                     {
4518                     if (tkn[0] == gapId || tkn[0] == missingId)
4519                         {
4520                         MrBayesPrint ("%s   Matching character matches gap or missing characters\n", spacer);
4521                         return (ERROR);
4522                         }
4523                     matchId = tkn[0];
4524                     }
4525                 else
4526                     {
4527                     MrBayesPrint ("%s   Invalid matchchar argument %s\n", spacer, tkn);
4528                     return (ERROR);
4529                     }
4530                 MrBayesPrint ("%s   Matching characters coded as %s\n", spacer, tkn);
4531                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4532                 }
4533             else
4534                 return (ERROR);
4535             }
4536         /* skip Symbols ***************************************************************/
4537         else if (!strcmp(parmName, "Symbols"))
4538             {
4539             if (expecting == Expecting(EQUALSIGN))
4540                 {
4541                 MrBayesPrint ("%s   WARNING: MrBayes does not support 'symbols' specification; default symbols assumed\n", spacer);
4542                 readWord=YES;
4543                 expecting = Expecting(ALPHA);
4544                 }
4545             else if (expecting == Expecting(ALPHA))
4546                 {
4547                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4548                 }
4549             else
4550                 return (ERROR);
4551             }
4552         /* on Equate return ERROR ***************************************************************/
4553         else if (!strcmp(parmName, "Equate"))
4554             {
4555             MrBayesPrint ("%s   ERROR: MrBayes does not support 'Equate' macros; please remove or comment out\n", spacer);
4556             return (ERROR);
4557             }
4558         else
4559             return (ERROR);
4560         }
4561
4562     return (NO_ERROR);
4563 }
4564
4565
4566 int DoHelp (void)
4567 {
4568     int         i, j, longestDescription;
4569     CmdType     *p;
4570
4571     if (foundFirst == NO)
4572         {
4573         longestDescription = 0;
4574         for (i=1; i<NUMCOMMANDS; i++)
4575             {
4576             p = commands + i;
4577             if ((int)strlen(p->string) > longestDescription)
4578                 longestDescription = (int) strlen(p->string);
4579             }
4580         
4581         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
4582         MrBayesPrint ("   Commands that are available from the command                                  \n");
4583         MrBayesPrint ("   line or from a MrBayes block include:                                         \n");
4584         MrBayesPrint ("                                                                                 \n");
4585         for (i=1; i<NUMCOMMANDS; i++)
4586             {
4587             p = commands + i;
4588             if (p->cmdUse == IN_CMD && p->hiding == SHOW)
4589                 {
4590                 MrBayesPrint ("   %s", p->string);
4591                 for (j=0; j<longestDescription - (int) strlen(p->string); j++)
4592                 MrBayesPrint (" ");
4593                 MrBayesPrint (" -- %s\n", p->cmdDescription);
4594                 }
4595             }
4596         MrBayesPrint ("                                                                                 \n");
4597         MrBayesPrint ("   Commands that should be in a NEXUS file (data                                 \n");
4598         MrBayesPrint ("   block, trees block or taxa block) include:                                                \n");
4599         MrBayesPrint ("                                                                                 \n");
4600         for (i=1; i<NUMCOMMANDS; i++)
4601             {
4602             p = commands + i;
4603             if (p->cmdUse == IN_FILE && p->hiding == SHOW)
4604                 {
4605                 MrBayesPrint ("   %s", p->string);
4606                 for (j=0; j<longestDescription - (int) strlen(p->string); j++)
4607                 MrBayesPrint (" ");
4608                 MrBayesPrint (" -- %s\n", p->cmdDescription);
4609                 }
4610             }
4611         MrBayesPrint ("                                                                                 \n");
4612         MrBayesPrint ("   Note that this program supports the use of the shortest unambiguous           \n"); 
4613         MrBayesPrint ("   spelling of the above commands (e.g., \"exe\" instead of \"execute\").        \n");
4614         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
4615         }
4616     foundFirst = NO;
4617
4618     return (NO_ERROR);
4619 }
4620
4621
4622 int DoHelpParm (char *parmName, char *tkn)
4623 {
4624     int         i, j, tkLen, targetLen, numDiff, numMatches;
4625     CmdType     *p, *q=NULL;
4626
4627     if (expecting == Expecting(ALPHA))
4628         {
4629         p = commands + 0;
4630         tkLen = (int) strlen(tkn);
4631         numMatches = 0;
4632         for (i=0; i<NUMCOMMANDS; i++)
4633             {
4634             targetLen = (int) strlen(p->string);
4635             if (tkLen <= targetLen)
4636                 {
4637                 for (j=0, numDiff=0; j<tkLen; j++)
4638                     {
4639                     if (ChangeCase(tkn[j]) != ChangeCase(p->string[j]))
4640                         numDiff++;
4641                     }
4642                 if (numDiff == 0)
4643                     {
4644                     numMatches++;
4645                     q = p;
4646                     if (tkLen == targetLen)
4647                         break;
4648                     }
4649                 }       
4650             p++;
4651             }
4652         if (numMatches == 0)
4653             {
4654             MrBayesPrint ("%s   Could not find command \"%s\"\n", spacer, tkn);
4655             return (ERROR);
4656             }
4657         else if (numMatches == 1)
4658             {
4659             if (GetUserHelp (q->string) == ERROR)
4660                 {
4661                 MrBayesPrint ("%s   Problem getting help for command \"%s\"\n", spacer, q->string);
4662                 }
4663             }
4664         else 
4665             {
4666             MrBayesPrint ("%s   Ambiguous command \"%s\"\n", spacer, tkn);
4667             return (ERROR);
4668             }
4669             
4670         expecting = Expecting(SEMICOLON);
4671         foundFirst = YES;
4672         }
4673     else
4674         return (ERROR);
4675
4676     return (NO_ERROR);
4677     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
4678 }
4679
4680
4681 int DoInclude (void)
4682 {
4683     int         i, alreadyDone;
4684
4685     MrBayesPrint ("%s   Including character(s)\n", spacer);
4686
4687     /* add set to tempSet */
4688     if (fromI >= 0 && toJ < 0)
4689         {
4690         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4691             return (ERROR);
4692         }
4693     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4694         {
4695         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4696             return (ERROR);
4697         }
4698     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4699         {
4700         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4701             return (ERROR);
4702         }
4703         
4704     /* merge tempSet with excludedChars */
4705     alreadyDone = NO;
4706     for (i=0; i<numChar; i++)
4707         {
4708         if (tempSet[i] == 1)
4709             {
4710             if (charInfo[i].isExcluded == NO && alreadyDone == NO)  
4711                 {
4712                 MrBayesPrint ("%s   Some characters already included\n", spacer);
4713                 alreadyDone = YES;
4714                 }
4715             charInfo[i].isExcluded = NO;
4716             }
4717         }
4718
4719     /* reset analysis to recompress data */
4720     if (SetUpAnalysis(&globalSeed) == ERROR)
4721         return ERROR;
4722
4723     return (NO_ERROR);
4724 }
4725
4726
4727 int DoIncludeParm (char *parmName, char *tkn)
4728 {
4729     int     i, index, tempInt;
4730         
4731     if (defMatrix == NO)
4732         {
4733         MrBayesPrint ("%s   A matrix must be specified before you can include characters\n", spacer);
4734         return (ERROR);
4735         }
4736         
4737     if (foundFirst == NO)
4738         {
4739         /* this is the first time in */
4740         fromI = toJ = everyK = -1;
4741         foundDash = foundSlash = NO;
4742         for (i=0; i<numChar; i++) /* clear tempSet */
4743             tempSet[i] = 0;
4744         foundFirst = YES;
4745         }
4746
4747     if (expecting == Expecting(ALPHA))
4748         {
4749         if (IsSame ("All", tkn) == SAME || IsSame ("All", tkn) == CONSISTENT_WITH)
4750             {
4751             for (i=0; i<numChar; i++)
4752                 tempSet[i] = 1;
4753             }
4754         else if (IsSame ("Missambig", tkn) == SAME || IsSame ("Missambig", tkn) == CONSISTENT_WITH)
4755             {
4756             for (i=0; i<numChar; i++)
4757                 {
4758                 if (charInfo[i].isMissAmbig == YES)
4759                     tempSet[i] = 1;
4760                 }
4761             }
4762         else
4763             {
4764             /* we are using a pre-defined character set */
4765             if (numCharSets < 1)
4766                 {
4767                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
4768                 return (ERROR);
4769                 }
4770             if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
4771                 {
4772                 MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
4773                 return (ERROR);
4774                 }
4775             /* add characters from charset tkn to new tempSet */
4776             for (i=0; i<numChar; i++)
4777                 {
4778                 if (IsBitSet(i, charSet[index]) == YES)
4779                     tempSet[i] = 1;
4780                 }
4781             fromI = toJ = everyK = -1;
4782             }
4783
4784         expecting  = Expecting(ALPHA);
4785         expecting |= Expecting(NUMBER);
4786         expecting |= Expecting(SEMICOLON);
4787         }
4788     else if (expecting == Expecting(NUMBER))
4789         {
4790         if (strlen(tkn) == 1 && tkn[0] == '.')
4791             tempInt = numChar;
4792         else
4793             sscanf (tkn, "%d", &tempInt);
4794         if (tempInt <= 0 || tempInt > numChar)
4795             {
4796             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
4797             return (ERROR);
4798             }
4799         tempInt--;
4800         if (foundDash == YES)
4801             {
4802             if (fromI >= 0)
4803                 toJ = tempInt;
4804             else
4805                 {
4806                 MrBayesPrint ("%s   Improperly formatted include set\n", spacer);
4807                 return (ERROR);
4808                 }
4809             foundDash = NO;
4810             }
4811         else if (foundSlash == YES)
4812             {
4813             tempInt++;
4814             if (tempInt <= 1)
4815                 {
4816                 MrBayesPrint ("%s   Improperly formatted include set\n", spacer);
4817                 return (ERROR);
4818                 }
4819             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
4820                 everyK = tempInt;
4821             else
4822                 {
4823                 MrBayesPrint ("%s   Improperly formatted include set\n", spacer);
4824                 return (ERROR);
4825                 }
4826             foundSlash = NO;
4827             }
4828         else
4829             {
4830             if (fromI >= 0 && toJ < 0)
4831                 {
4832                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4833                     return (ERROR);
4834                 fromI = tempInt;
4835                 }
4836             else if (fromI < 0 && toJ < 0)
4837                 {
4838                 fromI = tempInt;
4839                 }
4840             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
4841                 {
4842                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4843                     return (ERROR);
4844                 fromI = tempInt;
4845                 toJ = everyK = -1;
4846                 }
4847             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
4848                 {
4849                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
4850                     return (ERROR);
4851                 fromI = tempInt;
4852                 toJ = everyK = -1;
4853                 }
4854             else
4855                 {
4856                 MrBayesPrint ("%s   Improperly formatted include set\n", spacer);
4857                     {
4858                     return (ERROR);
4859                     }
4860                 }
4861             }
4862         expecting  = Expecting(ALPHA);
4863         expecting |= Expecting(NUMBER);
4864         expecting |= Expecting(SEMICOLON);
4865         expecting |= Expecting(DASH);
4866         expecting |= Expecting(BACKSLASH);
4867         }
4868     else if (expecting == Expecting(DASH))
4869         {
4870         foundDash = YES;
4871         expecting = Expecting(NUMBER);
4872         }
4873     else if (expecting == Expecting(BACKSLASH))
4874         {
4875         foundSlash = YES;
4876         expecting = Expecting(NUMBER);
4877         }
4878     else
4879         return (ERROR);
4880
4881     return (NO_ERROR);
4882     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
4883 }
4884
4885
4886 int DoLog (void)
4887 {
4888     if (logToFile == YES)
4889         {
4890         SafeFclose (&logFileFp);
4891         if (replaceLogFile == YES)
4892             {
4893             if ((logFileFp = OpenTextFileW (logFileName)) == NULL)  
4894                 {
4895                 logToFile = NO;
4896                 return (ERROR);
4897                 }
4898             }
4899         else
4900             {
4901             if ((logFileFp = OpenTextFileA (logFileName)) == NULL)  
4902                 {
4903                 logToFile = NO;
4904                 return (ERROR);
4905                 }
4906             }
4907         MrBayesPrint ("%s   Logging screen output to file \"%s\"\n", spacer, logFileName);
4908         }
4909     else
4910         {
4911         SafeFclose (&logFileFp);
4912         MrBayesPrint ("%s   Terminating log output\n", spacer);
4913         }
4914
4915     return (NO_ERROR);
4916 }
4917
4918
4919 int DoLogParm (char *parmName, char *tkn)
4920 {
4921     if (expecting == Expecting(PARAMETER))
4922         {
4923         if (!strcmp(parmName, "Start"))
4924             {
4925             if (logToFile == YES)
4926                 MrBayesPrint ("%s   Logging to file is already on\n", spacer, logFileName);
4927             else
4928                 logToFile = YES;
4929             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4930             }
4931         else if (!strcmp(parmName, "Stop"))
4932             {
4933             if (logToFile == NO)
4934                 MrBayesPrint ("%s   Logging to file is already off\n", spacer, logFileName);
4935             else
4936                 logToFile = NO;
4937             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4938             }
4939         else if (!strcmp(parmName, "Replace"))
4940             {
4941             replaceLogFile = YES;
4942             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4943             }
4944         else if (!strcmp(parmName, "Append"))
4945             {
4946             replaceLogFile = NO;
4947             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4948             }
4949         else
4950             expecting = Expecting(EQUALSIGN);
4951         }
4952     else
4953         {
4954         if (!strcmp(parmName, "Filename"))
4955             {
4956             if (expecting == Expecting(EQUALSIGN))
4957                 {
4958                 expecting = Expecting(ALPHA);
4959                 readWord = YES;
4960                 }
4961             else if (expecting == Expecting(ALPHA))
4962                 {
4963                 strcpy (logFileName, tkn);
4964                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4965                 }
4966             else
4967                 return (ERROR);
4968             }
4969         else
4970             {
4971             MrBayesPrint ("%s   Unknown parameter in Log\n", spacer);
4972             return (ERROR);
4973             }
4974         }
4975
4976     return (NO_ERROR);
4977 }
4978
4979
4980 int DoManual (void)
4981 {
4982     int     i, j, logSetting;
4983     char    title[100];
4984     FILE    *fp, *logfp;
4985     CmdType *p;
4986     
4987     /* try to open file, return error if present */
4988     if ((fp = OpenTextFileRQuait(manFileName)) != NULL)
4989         {
4990         MrBayesPrint ("%s   File \"%s\" already exists \n", spacer, manFileName);
4991         SafeFclose(&fp);
4992         return (ERROR);
4993         }
4994
4995     /* try to open file for writing, return error if not possible */
4996     if ((fp = OpenTextFileW(manFileName)) == NULL)
4997         return (ERROR);
4998
4999     /* print message */
5000     MrBayesPrint ("%s   Producing command reference file \"%s\"\n", spacer, manFileName);
5001
5002     /* temporarily disable normal logging and switch echoing off */
5003     logSetting = logToFile;
5004     logfp = logFileFp;
5005     echoMB = NO;
5006     logToFile = YES;
5007     logFileFp = fp;
5008     
5009     /* produce command reference file */
5010     /* header */
5011     strcpy (title, "Command Reference for MrBayes ver. ");
5012     strcat (title, VERSION_NUMBER);
5013
5014     i = (70 - (int) strlen (title)) / 2;
5015     j = 70 - i - (int) strlen(title);
5016
5017     MrBayesPrint ("                                                                                 \n");
5018     MrBayesPrint ("                                                                                 \n");
5019     MrBayesPrint ("                                                                                 \n");
5020     MrBayesPrint ("                                                                                 \n");
5021     MrBayesPrint ("      %*c%s%*c      \n", i, ' ', title, j, ' ');
5022     MrBayesPrint ("                                                                                 \n");
5023     MrBayesPrint ("                   (c) John P. Huelsenbeck, Fredrik Ronquist                     \n");
5024     MrBayesPrint ("                               and Maxim Teslenko                                \n");
5025     MrBayesPrint ("                                                                                 \n");
5026
5027     /* summary */
5028     MrBayesPrint ("                                                                                 \n");
5029     MrBayesPrint ("   ***************************************************************************   \n");
5030     MrBayesPrint ("   *                                                                         *   \n");
5031     MrBayesPrint ("   *  1. Command summary                                                     *   \n");
5032     MrBayesPrint ("   *                                                                         *   \n");
5033     MrBayesPrint ("   ***************************************************************************   \n");
5034     MrBayesPrint ("                                                                                 \n");
5035     foundFirst = NO;
5036     if (DoHelp() == ERROR)
5037         {
5038         MrBayesPrint ("%s   Could not produce command reference summary\n", spacer);
5039         goto errorExit;
5040         }
5041     
5042     /* list of MrBayes commands */
5043     MrBayesPrint ("                                                                                 \n");
5044     MrBayesPrint ("   ***************************************************************************   \n");
5045     MrBayesPrint ("   *                                                                         *   \n");
5046     MrBayesPrint ("   *  2. MrBayes commands                                                    *   \n");
5047     MrBayesPrint ("   *                                                                         *   \n");
5048     MrBayesPrint ("   ***************************************************************************   \n");
5049     MrBayesPrint ("                                                                                 \n");
5050     for (i=1; i<NUMCOMMANDS; i++)
5051         {
5052         p = commands + i;
5053         if (p->cmdUse == IN_CMD && p->hiding == SHOW)
5054             {
5055             if (GetUserHelp(p->string)==ERROR)
5056                 goto errorExit;
5057             }
5058         }
5059
5060     /* list of data or tree block commands */
5061     MrBayesPrint ("                                                                                 \n");
5062     MrBayesPrint ("   ***************************************************************************   \n");
5063     MrBayesPrint ("   *                                                                         *   \n");
5064     MrBayesPrint ("   *  3. 'Data' or 'tree' block commands (in #NEXUS file)                    *   \n");
5065     MrBayesPrint ("   *                                                                         *   \n");
5066     MrBayesPrint ("   ***************************************************************************   \n");
5067     MrBayesPrint ("                                                                                 \n");
5068     for (i=1; i<NUMCOMMANDS; i++)
5069         {
5070         p = commands + i;
5071         if (p->cmdUse == IN_FILE && p->hiding == SHOW)
5072             {
5073             if (GetUserHelp(p->string) == ERROR)
5074                 goto errorExit;
5075             }
5076         }
5077
5078     /* return logging to previous setings and switch echoing on */
5079     SafeFclose (&fp);
5080     logToFile = logSetting;
5081     logFileFp = logfp;
5082     echoMB = YES;
5083
5084     MrBayesPrint ("%s   Successfully produced command reference file \"%s\"\n", spacer, manFileName);
5085
5086     return (NO_ERROR);
5087
5088     errorExit:
5089         SafeFclose (&fp);
5090         logToFile = logSetting;
5091         logFileFp = logfp;
5092         echoMB = YES;
5093
5094         return (ERROR);
5095 }
5096
5097
5098 int DoManualParm (char *parmName, char *tkn)
5099 {
5100     if (expecting == Expecting(PARAMETER))
5101         {
5102         expecting = Expecting(EQUALSIGN);
5103         }
5104     else
5105         {
5106         if (!strcmp(parmName, "Filename"))
5107             {
5108             if (expecting == Expecting(EQUALSIGN))
5109                 {
5110                 expecting = Expecting(ALPHA);
5111                 readWord = YES;
5112                 }
5113             else if (expecting == Expecting(ALPHA))
5114                 {
5115                 strcpy (manFileName, tkn);
5116                 expecting = Expecting(SEMICOLON);
5117                 }
5118             else
5119                 return (ERROR);
5120             }
5121         else
5122             {
5123             MrBayesPrint ("%s   Unknown parameter in Manual\n", spacer);
5124             return (ERROR);
5125             }
5126         }
5127
5128     return (NO_ERROR);
5129 }
5130
5131
5132 int DoMatrix (void)
5133 {
5134     int         i, j, hasMissingAmbig;
5135     
5136     if (taxonCount != numTaxa)
5137         {
5138         MrBayesPrint ("%s   Problem with number of taxa read in (%d taxa read in, while expecting %d)\n", spacer, taxonCount, numTaxa);
5139         FreeMatrix();
5140         return (ERROR);
5141         }
5142     for (i=0; i<numTaxa; i++)
5143         {
5144         if (taxaInfo[i].charCount != numChar)
5145             {
5146             MrBayesPrint ("%s   Problem with number of characters read in (%d expected for taxon %d, %d read in)\n", spacer, numChar, i, taxaInfo[i].charCount);
5147             FreeMatrix();
5148             return (ERROR);
5149             }
5150         }
5151         
5152     /* find out which characters have missing or ambiguous states (one time only, so no special function) */
5153     for (i=0; i<numChar; i++)
5154         {
5155         hasMissingAmbig = NO;
5156         for (j=0; j<numTaxa; j++)
5157             {
5158             if (IsMissing (matrix[pos(j,i,numChar)], charInfo[i].charType) == YES)
5159                 hasMissingAmbig = YES;
5160             if (IsAmbig (matrix[pos(j,i,numChar)], charInfo[i].charType) == YES)
5161                 hasMissingAmbig = YES;
5162             }
5163         if (hasMissingAmbig == YES)
5164             charInfo[i].isMissAmbig = YES;
5165         }
5166
5167     MrBayesPrint ("%s   Successfully read matrix\n", spacer);
5168     if (matrixHasPoly == YES)
5169         MrBayesPrint ("%s   Matrix contains polymorphisms, interpreted as ambiguity\n", spacer);
5170     defMatrix = YES;
5171     isTaxsetDef = YES;
5172
5173     /* add name of default partition */
5174     if (AddString (&partitionNames, 0, "Default") == ERROR)
5175         {
5176         MrBayesPrint ("%s   Problem adding Default name to partition list\n", spacer);
5177         return (ERROR);
5178         }
5179     numDefinedPartitions = 1;
5180
5181     if (numDefinedSpeciespartitions == 0)   /* the default species partition could have been added already in DoTaxLabels */
5182         {
5183         /* add default speciespartition name to list of valid speciespartitions */
5184         if (AddString (&speciespartitionNames, 0, "Default") == ERROR)
5185             {
5186             MrBayesPrint ("%s   Problem adding Default speciespartition to list\n", spacer);
5187             return (ERROR);
5188             }
5189
5190         /* add default species name set */
5191         AddNameSet(&speciesNameSets, 0, taxaNames, numTaxa);
5192
5193         /* set number of defined speciespartitions to 1 */
5194         numDefinedSpeciespartitions = 1;
5195         }
5196         
5197     if (SetPartition (0) == ERROR)
5198         return ERROR;
5199
5200     if (SetSpeciespartition (0) == ERROR)
5201         return ERROR;
5202
5203     if (numCurrentDivisions == 1)
5204         MrBayesPrint ("%s   Setting default partition (does not divide up characters)\n", spacer);
5205     else
5206         MrBayesPrint ("%s   Setting default partition, dividing characters into %d parts\n", spacer, numCurrentDivisions);
5207     
5208     if (SetModelDefaults () == ERROR)
5209         return (ERROR);
5210
5211     if (SetUpAnalysis (&globalSeed) == ERROR)
5212         return (ERROR);
5213
5214     /* set default names for some output file names based on processed file */
5215     strcpy (sumtParams.sumtFileName, inputFileName);
5216     strcpy (sumtParams.sumtOutfile, inputFileName);
5217     strcpy (sumpParams.sumpFileName, inputFileName);
5218     strcpy (sumpParams.sumpOutfile, inputFileName);
5219     strcpy (comptreeParams.comptOutfile, inputFileName);
5220
5221     if (chainParams.numRuns == 1)
5222         {
5223         sprintf (comptreeParams.comptFileName1, "%s.t", inputFileName);
5224         sprintf (comptreeParams.comptFileName2, "%s.t", inputFileName);
5225         }
5226     else /* if (chainParams.numRuns > 1) */
5227         {
5228         sprintf (comptreeParams.comptFileName1, "%s.run1.t", inputFileName);
5229         sprintf (comptreeParams.comptFileName2, "%s.run2.t", inputFileName);
5230         }
5231
5232     if (chainParams.numRuns == 1)
5233         sprintf (plotParams.plotFileName, "%s.p", inputFileName);
5234     else /* if (chainParams.numRuns > 1) */
5235         sprintf (plotParams.plotFileName, "%s.run1.p", inputFileName);
5236
5237     strcpy (chainParams.chainFileName, inputFileName);
5238
5239     if (chainParams.numRuns > 1)
5240         MrBayesPrint ("%s   Setting output file names to \"%s.run<i>.<p|t>\"\n", spacer, chainParams.chainFileName);
5241     else
5242         MrBayesPrint ("%s   Setting output file names to \"%s.<p|t>\"\n", spacer, chainParams.chainFileName);
5243
5244 #   if 0
5245     for (i=0; i<numChar; i++)
5246         {
5247         int     j;
5248         MrBayesPrint ("%4d -- ", i+1);
5249         for (j=0; j<numTaxa; j++)
5250             MrBayesPrint ("%2d ", matrix[pos(j,i,numChar)]);
5251         MrBayesPrint ("\n");
5252         }
5253 #   endif
5254
5255     return (NO_ERROR);
5256 }
5257
5258
5259 int DoMatrixParm (char *parmName, char *tkn)
5260 {
5261     int             i, j, charCode=0, index;
5262     MrBFlt          charValue;
5263
5264     expecting  = Expecting(ALPHA);
5265     expecting |= Expecting(QUESTIONMARK);
5266     expecting |= Expecting(DASH);
5267     expecting |= Expecting(NUMBER);
5268     expecting |= Expecting(ASTERISK);
5269     expecting |= Expecting(EXCLAMATIONMARK);
5270     expecting |= Expecting(PERCENT);
5271     expecting |= Expecting(WEIRD);
5272     expecting |= Expecting(VERTICALBAR);
5273     expecting |= Expecting(SEMICOLON);
5274     expecting |= Expecting(LEFTPAR);
5275     expecting |= Expecting(RIGHTPAR);
5276     expecting |= Expecting(LEFTCURL);
5277     expecting |= Expecting(RIGHTCURL);
5278
5279     if (defTaxa == NO || defChars == NO)
5280         {
5281         MrBayesPrint ("%s   Number of taxa and characters needs to be defined before matrix is read\n", spacer);
5282         goto errorExit;
5283         }
5284     if (inDataBlock == NO && inCharactersBlock == NO)
5285         {
5286         MrBayesPrint ("%s   Must be in data or characters block to read in character matrix\n", spacer);
5287         goto errorExit;
5288         }
5289
5290     if (isFirstMatrixRead == YES)
5291         {
5292         foundNewLine = YES;
5293         isFirstInterleavedBlock = YES;
5294         taxonCount = 0;
5295         isNegative = NO;
5296         }
5297     isFirstMatrixRead = NO;
5298     
5299     /* allow line breaks in non-interleaved matrices */
5300     if (isInterleaved == NO)
5301         {
5302         if (foundNewLine == YES && taxonCount > 0)
5303             {
5304             if (taxaInfo[taxonCount-1].charCount < numChar)
5305                 foundNewLine = NO;
5306             }
5307         }
5308
5309     if (taxonCount >= numTaxa && foundNewLine == YES)
5310         {
5311         if (isInterleaved == YES)
5312             {
5313             taxonCount = 0;
5314             isFirstInterleavedBlock = NO;
5315             }
5316         else
5317             {
5318             MrBayesPrint ("%s   Too many taxa in matrix\n", spacer);
5319             goto errorExit;
5320             }
5321         }
5322     
5323     if (taxaInfo[0].charCount > 4010)
5324         i = 1;
5325
5326     if (foundNewLine == YES)
5327         {
5328         /* Should be a taxon. */
5329         if (isFirstInterleavedBlock == YES)
5330             {
5331             /* If this is the first interleaved block, then we need to add the taxon
5332                to the set of taxon names unless there is already a defined taxon set. */
5333             if (strlen(tkn)>99)
5334                 {
5335                 MrBayesPrint ("%s   Taxon name %s is too long. Maximun 99 characters is allowed.\n", spacer, tkn);
5336                 goto errorExit;
5337                 }
5338             if (isTaxsetDef == NO && AddString (&taxaNames, taxonCount, tkn) == ERROR)
5339                 {
5340                 MrBayesPrint ("%s   Problem adding taxon %s to taxon set\n", spacer, tkn);
5341                 goto errorExit;
5342                 }
5343             if (numTaxa < 10)
5344                 MrBayesPrint ("%s   Taxon %d -> %s\n", spacer, taxonCount+1, tkn);
5345             else if (numTaxa < 100 && numTaxa >= 10)
5346                 MrBayesPrint ("%s   Taxon %2d -> %s\n", spacer, taxonCount+1, tkn);
5347             else if (numTaxa < 1000 && numTaxa >= 100)
5348                 MrBayesPrint ("%s   Taxon %3d -> %s\n", spacer, taxonCount+1, tkn);
5349             else
5350                 MrBayesPrint ("%s   Taxon %4d -> %s\n", spacer, taxonCount+1, tkn);
5351             }
5352         else
5353             {
5354             /* If this is not the first interleaved block, then we need to
5355                check to see if taxon name is present and in correct place. */
5356             if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
5357                 {
5358                 MrBayesPrint ("%s   Could not find taxon %s in list of taxa\n", spacer, tkn);
5359                 goto errorExit;
5360                 }
5361             if (index != taxonCount)
5362                 {
5363                 MrBayesPrint ("%s   Could not find taxon %s in correct position in list of taxa\n", spacer, tkn);
5364                 goto errorExit;
5365                 }
5366             }
5367         foundNewLine = NO;
5368         isNegative = NO;
5369         taxonCount++;
5370         }
5371     else
5372         {
5373         /* Should be a character (either continuous or otherwise). */
5374         if (charInfo[taxaInfo[taxonCount-1].charCount].charType == CONTINUOUS)
5375             {
5376             /* If we have a CONTINUOUS character, then the entire token should either be
5377                a number or a dash (for a negative sign). */
5378             if (!strcmp(tkn, "-"))
5379                 {
5380                 /* Dealing with a negative number. We will multiply the next tkn, which
5381                    had better be a number, by -1. */
5382                 isNegative = YES;
5383                 }
5384             else
5385                 {
5386                 /* We have a number, we hope. */
5387                 if (tkn[0] == matchId)
5388                     {
5389                     /* If the token is a matchchar, then things are simple. */
5390                     if (taxonCount == 1)
5391                         {
5392                         MrBayesPrint ("%s   Matching characters cannot be in first taxon\n", spacer);
5393                         goto errorExit;
5394                         }
5395                     charCode = matrix[pos(0,taxaInfo[taxonCount-1].charCount,numChar)];
5396                     matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount,numChar)] = charCode;
5397                     }
5398                 else
5399                     {
5400                     /* Otherwise, we have a number. Check that it is a valid number first... */
5401                     if (!IsIn(tkn[0],"0123456789."))
5402                         {
5403                         MrBayesPrint ("%s   Expecting a number for the continuous character\n", spacer);
5404                         goto errorExit;
5405                         }
5406                     /* ... and then put the character into the matrix. Note that matrix
5407                        is defined as an integer, but we may have floating precision continuous
5408                        characters. To get around this, we multiply the value of the character
5409                        by 1000 before putting it into matrix. We will divide by 1000 later on
5410                        when/if we use the characters. */
5411                     sscanf (tkn, "%lf", &charValue);
5412                     charValue *= 1000.0;
5413                     if (isNegative == YES)
5414                         {
5415                         charValue *= -1.0;
5416                         isNegative = NO;
5417                         }
5418                     /*MrBayesPrint ("%d \n", (int)charValue);*/
5419                     matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = (int)charValue;
5420                     }
5421                 }
5422             }
5423         else
5424             {
5425             /* Otherwise, we are dealing with a run-of-the-mill character, and we
5426                cannot expect the entire token to contain only a single character. We
5427                must, therefore, go through the token character-by-character. */
5428             i = 0;
5429             while (tkn[i] != '\0')
5430                 {
5431                 /*MrBayesPrint ("%c", tkn[i]);*/
5432                 if (tkn[i] == matchId)
5433                     {
5434                     if (taxonCount == 1)
5435                         {
5436                         MrBayesPrint ("%s   Matching characters cannot be in first taxon\n", spacer);
5437                         goto errorExit;
5438                         }
5439                     charCode = matrix[pos(0,taxaInfo[taxonCount-1].charCount,numChar)];
5440                     matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = charCode;
5441                     }
5442                 else
5443                     {
5444                     if ((tkn[i] == ')' && isInAmbig == YES) || (tkn[i] == '}' && isInPoly == YES))
5445                         {
5446                         isInAmbig = isInPoly = NO;
5447                         charCode = theAmbigChar;
5448                         j = CharacterNumber (charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType);
5449                         if (j > charInfo[taxaInfo[taxonCount-1].charCount].numStates)
5450                             charInfo[taxaInfo[taxonCount-1].charCount].numStates = j;
5451                         matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = charCode;
5452                         theAmbigChar = 0;
5453                         }
5454                     else if ((tkn[i] == '(' && isInAmbig == YES) || (tkn[i] == '{' && isInPoly == YES))
5455                         {
5456                         if (isInAmbig == YES)
5457                             MrBayesPrint ("%s   Found an inappropriate \"(\"\n", spacer);
5458                         else
5459                             MrBayesPrint ("%s   Found an inappropriate \"{\"\n", spacer);
5460                         goto errorExit;
5461                         }
5462                     else if (isInAmbig == YES || isInPoly == YES)
5463                         {
5464                         if (tkn[i] == ',')
5465                             expecting |= Expecting (COMMA);
5466                         else 
5467                             {
5468                             if (CharacterCode(tkn[i], &charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType) == ERROR)
5469                                 goto errorExit;
5470                             if (charCode == MISSING || charCode == GAP)
5471                                 goto errorExit;
5472                             theAmbigChar |= charCode;
5473                             expecting ^= Expecting (COMMA);
5474                             }
5475                         }
5476                     else if (tkn[i] == '{' && isInPoly == NO && isInAmbig == NO)
5477                         {
5478                         isInPoly = YES;
5479                         matrixHasPoly = YES;
5480                         theAmbigChar = 0;
5481                         }   
5482                     else if (tkn[i] == '(' && isInPoly == NO && isInAmbig == NO)
5483                         {
5484                         isInAmbig = YES;
5485                         theAmbigChar = 0;
5486                         }
5487                     else if (tkn[i] == '(' && isInPoly == NO && isInAmbig == NO)
5488                         {
5489                         isInAmbig = YES;
5490                         theAmbigChar = 0;
5491                         }
5492                     else
5493                         {
5494                         if (CharacterCode(tkn[i], &charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType) == ERROR)
5495                             {
5496                             MrBayesPrint ("%s   Error while reading character position %d (charCode %d)\n", spacer, taxaInfo[taxonCount-1].charCount+1, charCode);
5497                             goto errorExit;
5498                             }
5499                         if (charCode != MISSING && charCode != GAP)
5500                             {
5501                             j = CharacterNumber (charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType);
5502                             if (j > charInfo[taxaInfo[taxonCount-1].charCount].numStates)
5503                                 charInfo[taxaInfo[taxonCount-1].charCount].numStates = j;
5504                             }
5505                         matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = charCode;
5506                         }
5507                     }
5508                 i++; 
5509                 }
5510             }
5511         }
5512
5513     return (NO_ERROR);
5514     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
5515     errorExit:
5516         numTaxa=taxonCount;
5517         FreeMatrix();
5518         return (ERROR);
5519 }
5520
5521
5522 int DoNexusParm (char *parmName, char *tkn)
5523 {
5524     if (!strcmp(parmName, "NEXUS"))
5525         {
5526         MrBayesPrint ("%s   Expecting NEXUS formatted file\n", spacer);
5527         expecting = Expecting(COMMAND);
5528         }
5529     else
5530         {
5531         MrBayesPrint ("%s   Found %s\n", spacer, tkn);
5532         return (ERROR);
5533         }
5534     
5535     return (NO_ERROR);
5536 }
5537
5538
5539 int DoOutgroup (void)
5540 {
5541     MrBayesPrint ("%s   Setting outgroup to taxon \"%s\"\n", spacer, taxaNames[outGroupNum]);
5542     return (NO_ERROR);
5543 }
5544
5545
5546 int DoOutgroupParm (char *parmName, char *tkn)
5547 {
5548     int     index, tempInt;
5549
5550     if (expecting == Expecting(ALPHA))
5551         {
5552         if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
5553             {
5554             MrBayesPrint ("%s   Could not find taxon %s in list of taxa\n", spacer, tkn);
5555             return (ERROR);
5556             }
5557         outGroupNum = index;
5558         
5559         expecting = Expecting(SEMICOLON);
5560         }
5561     else if (expecting == Expecting(NUMBER))
5562         {
5563         if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
5564             {
5565             /* OK, as we expect, the taxon is not a digit. So, now we assume that
5566                the user is assigning the outgroup by its number */
5567             sscanf (tkn, "%d", &tempInt);
5568             if (tempInt < 1 || tempInt > numTaxa)
5569                 {
5570                 MrBayesPrint ("%s   Taxon number %d is out of range\n", spacer, tempInt);
5571                 return (ERROR);
5572                 }
5573             outGroupNum = tempInt - 1;
5574             }
5575         else
5576             {
5577             outGroupNum = index;
5578             }
5579         
5580         expecting = Expecting(SEMICOLON);
5581         }
5582     else
5583         return (ERROR);
5584
5585     return (NO_ERROR);
5586     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
5587 }
5588
5589
5590 int DoPairs (void)
5591 {
5592     MrBayesPrint ("\n");
5593     MrBayesPrint ("%s   Successfully defined character pairings\n", spacer);
5594
5595     defPairs = YES;
5596     foundFirst = NO;
5597     
5598     return (NO_ERROR);
5599 }
5600
5601
5602 int DoPairsParm (char *parmName, char *tkn)
5603 {
5604     int     i, tempInt;
5605         
5606     if (defMatrix == NO)
5607         {
5608         MrBayesPrint ("%s   A matrix must be specified before you can define pairs of characters\n", spacer);
5609         return (ERROR);
5610         }
5611     
5612     if (defPairs == YES)
5613         {
5614         MrBayesPrint ("%s   Character pairs have been previously defined \n", spacer);
5615         MrBayesPrint ("%s   Now overwriting old pairings\n", spacer);
5616         for (i=0; i<numChar; i++)
5617             charInfo[i].pairsId = 0;
5618         defPairs = NO;
5619         }
5620         
5621     if (foundFirst == NO)
5622         {
5623         /* this is the first time in */
5624         pairId = 1;
5625         firstPair = YES;
5626         foundFirst = YES;
5627         MrBayesPrint ("%s   Defining character pairings:\n\n", spacer);
5628         MrBayesPrint ("%s      Pair --  First Second \n", spacer);
5629         }
5630
5631     if (expecting == Expecting(NUMBER))
5632         {
5633         sscanf (tkn, "%d", &tempInt);
5634         if (tempInt <= 0 || tempInt > numChar)
5635             {
5636             MrBayesPrint ("\n");
5637             MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
5638             for (i=0; i<numChar; i++)
5639                 charInfo[i].pairsId = 0;
5640             return (ERROR);
5641             }
5642         tempInt--;
5643         
5644         if (charInfo[tempInt].pairsId != 0)
5645             {
5646             MrBayesPrint ("\n");
5647             MrBayesPrint ("%s   Character number %d has already been included in a pairing\n", spacer, tempInt+1);
5648             for (i=0; i<numChar; i++)
5649                 charInfo[i].pairsId = 0;
5650             return (ERROR);
5651             }
5652         if (charInfo[tempInt].charType != DNA && charInfo[tempInt].charType != RNA)
5653             {
5654             MrBayesPrint ("\n");
5655             MrBayesPrint ("%s  Pairings may only include nucleotide data\n", spacer);
5656             if (charInfo[tempInt].charType == PROTEIN)
5657                 MrBayesPrint ("%s  Character %d is an amino acid character\n", spacer, tempInt+1);
5658             else if (charInfo[tempInt].charType == RESTRICTION)
5659                 MrBayesPrint ("%s  Character %d is a restriction site character\n", spacer, tempInt+1);
5660             else if (charInfo[tempInt].charType == STANDARD)
5661                 MrBayesPrint ("%s  Character %d is a \"standard\" character\n", spacer, tempInt+1);
5662             else if (charInfo[tempInt].charType == CONTINUOUS)
5663                 MrBayesPrint ("%s  Character %d is a continuously varying character\n", spacer, tempInt+1);
5664             for (i=0; i<numChar; i++)
5665                 charInfo[i].pairsId = 0;
5666             return (ERROR);
5667             }
5668             
5669         charInfo[tempInt].pairsId = pairId;
5670         
5671         if (firstPair == YES)
5672             {
5673             MrBayesPrint ("%s      %4d --  %5d  ", spacer, pairId, tempInt+1);
5674             expecting  = Expecting(COLON);
5675             firstPair = NO;
5676             }
5677         else
5678             {
5679             MrBayesPrint ("%5d\n", tempInt+1);
5680             expecting  = (Expecting(COMMA) | Expecting(SEMICOLON));
5681             firstPair = YES;
5682             }
5683         }
5684     else if (expecting == Expecting(COMMA))
5685         {
5686         pairId++;
5687         expecting = Expecting(NUMBER);
5688         }
5689     else if (expecting == Expecting(COLON))
5690         {
5691         expecting = Expecting(NUMBER);
5692         }
5693     else
5694         {
5695         for (i=0; i<numChar; i++)
5696             charInfo[i].pairsId = 0;
5697         return (ERROR);
5698         }
5699
5700     return (NO_ERROR);
5701     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
5702 }
5703
5704
5705 int DoPartition (void)
5706 {
5707     int     i, *partTypes;
5708         
5709     /* add set to tempSet */
5710     if (fromI >= 0)
5711         if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
5712             return (ERROR);
5713
5714     /* check that all characters are included */
5715     for (i=0; i<numChar; i++)
5716         {
5717         /* MrBayesPrint ("%4d %4d \n", i, tempSet[i]); */
5718         if (tempSet[i] == 0)
5719             {
5720             MrBayesPrint ("%s   Character %d not included in partition\n", spacer, i+1);
5721             return (ERROR);
5722             }
5723         }
5724
5725             
5726     /* check how many partitions were found against how many were expected */
5727     if (whichPartition != numDivisions - 1)
5728         {
5729         MrBayesPrint ("%s   Did not find correct number of partitions (expecting %d, found %d)\n", spacer, numDivisions, whichPartition + 1);
5730         return (ERROR);
5731         }
5732
5733     partTypes = (int *) SafeCalloc (numDivisions, sizeof(int));
5734     if (!partTypes)
5735         return ERROR;
5736     
5737     /* make certain that the partition labels go from 1 - numDivisions, inclusive */
5738     for (i=0; i<numChar; i++)
5739         partTypes[tempSet[i] - 1] = -1; //partTypes is temporary used here not as an indicator of partition type 
5740     for (i=0; i<numDivisions; i++)
5741         {
5742         if (partTypes[i] == 0)
5743             {
5744             MrBayesPrint ("%s   Could not find a single character for division %d\n", spacer, i+1);
5745             return (ERROR);
5746             }
5747         }
5748
5749     /* check if partition overruns data types */
5750     for (i=0; i<numChar; i++)
5751         {
5752         if (partTypes[ tempSet[i]-1 ] == -1)
5753             partTypes[ tempSet[i]-1 ] = charInfo[i].charType;
5754         else
5755             {
5756             if (partTypes[ tempSet[i]-1 ] != charInfo[i].charType)
5757                 {
5758                 MrBayesPrint ("%s   There are two different data types for partition division %d\n", spacer, tempSet[i]);
5759                 free (partTypes);
5760                 return (ERROR);
5761                 }
5762             }
5763         }
5764     free (partTypes);
5765
5766     /* add name to list of valid partitions */
5767     if (AddString (&partitionNames, numDefinedPartitions, tempSetName) == ERROR)
5768         {
5769         MrBayesPrint ("%s   Problem adding partition %s to list\n", spacer, tempSetName);
5770         return (ERROR);
5771         }
5772         
5773     /* add new partition */
5774     for (i=0; i<numChar; i++) {
5775         partitionId[i] = (int *) SafeRealloc ((void *)(partitionId[i]), ((size_t)numDefinedPartitions + 1) * sizeof(int));
5776         if (!partitionId[i])
5777             return ERROR;
5778     }
5779
5780     /* set new partition */
5781     for (i=0; i<numChar; i++)
5782         partitionId[i][numDefinedPartitions] = tempSet[i];
5783
5784     /* increment number of defined partitions */
5785     numDefinedPartitions++;
5786     
5787     return (NO_ERROR);
5788 }
5789
5790
5791 int DoPartitionParm (char *parmName, char *tkn)
5792 {
5793     int     i, index, tempInt;
5794     
5795     if (defMatrix == NO)
5796         {
5797         MrBayesPrint ("%s   A matrix must be specified before partitions can be defined\n", spacer);
5798         return (ERROR);
5799         }
5800
5801     if (expecting == Expecting(PARAMETER))
5802         {
5803         /* set Partition () ******************************************************************/
5804         if (!strcmp(parmName, "Xxxxxxxxxx"))
5805             {
5806             /* check size of partition name */
5807             if (strlen(tkn) > 99)
5808                 {
5809                 MrBayesPrint ("%s   Partition name is too long. Max 100 characters\n", spacer);
5810                 return (ERROR);
5811                 }
5812                 
5813             /* check to see if the name has already been used as a partition */
5814             if (numDefinedPartitions > 1)
5815                 {
5816                 if (CheckString (partitionNames, numDefinedPartitions, tkn, &index) == ERROR)
5817                     {
5818                     /* if the partition name has not been used, then we should have an ERROR returned */
5819                     /* we _want_ to be here */
5820
5821                     }
5822                 else
5823                     {
5824                     MrBayesPrint ("%s   Partition name '%s' has been used previously\n", spacer, tkn);
5825                     return (ERROR);
5826                     }
5827                 }
5828                 
5829             /* add the name temporarily to tempSetName */
5830             strcpy (tempSetName, tkn);
5831             
5832             /* clear tempSet */
5833             for (i=0; i<numChar; i++)
5834                 tempSet[i] = 0;
5835             
5836             fromI = toJ = everyK = -1;
5837             foundDash = foundSlash = NO;
5838             whichPartition = 0;
5839             foundFirst = NO;
5840             numDivisions = 0;
5841             MrBayesPrint ("%s   Defining partition called '%s'\n", spacer, tkn);
5842             expecting = Expecting(EQUALSIGN);
5843             }
5844         else
5845             return (ERROR);
5846         }
5847     else if (expecting == Expecting(EQUALSIGN))
5848         {
5849         expecting = Expecting(NUMBER);
5850         }
5851     else if (expecting == Expecting(ALPHA))
5852         {
5853         /* We are defining a partition in terms of a character set (called tkn, here). We should be able
5854            to find tkn in the list of character set names. If we cannot, then we have a problem and
5855            return an error. */
5856         if (numCharSets < 1)
5857             {
5858             MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
5859             return (ERROR);
5860             }
5861         if (CheckString (charSetNames, numCharSets, tkn, &index) == ERROR)
5862             {
5863             MrBayesPrint ("%s   Could not find a character set called '%s'\n", spacer, tkn);
5864             return (ERROR);
5865             }
5866         /* add characters from charset tkn to new tempSet */
5867         for (i=0; i<numChar; i++)
5868             {
5869             if (IsBitSet (i, charSet[index]) == YES)
5870                 tempSet[i] = whichPartition + 1;
5871             }
5872         fromI = toJ = everyK = -1;
5873
5874         expecting  = Expecting(ALPHA);
5875         expecting |= Expecting(NUMBER);
5876         expecting |= Expecting(SEMICOLON);
5877         expecting |= Expecting(COMMA);
5878         }
5879     else if (expecting == Expecting(NUMBER))
5880         {
5881         if (foundFirst == NO)
5882             {
5883             sscanf (tkn, "%d", &tempInt);
5884             numDivisions = tempInt;
5885             expecting  = Expecting(COLON);
5886             foundFirst = YES;
5887             }
5888         else
5889             {
5890             if (strlen(tkn) == 1 && tkn[0] == '.')
5891                 tempInt = numChar;
5892             else
5893                 sscanf (tkn, "%d", &tempInt);
5894             if (tempInt <= 0 || tempInt > numChar)
5895                 {
5896                 MrBayesPrint ("%s   Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar);
5897                 return (ERROR);
5898                 }
5899             tempInt--;
5900             if (foundDash == YES)
5901                 {
5902                 if (fromI >= 0)
5903                     toJ = tempInt;
5904                 else
5905                     {
5906                     MrBayesPrint ("%s   Improperly formatted partition\n", spacer);
5907                     return (ERROR);
5908                     }
5909                 foundDash = NO;
5910                 }
5911             else if (foundSlash == YES)
5912                 {
5913                 tempInt++;
5914                 if (tempInt <= 1)
5915                     {
5916                     MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
5917                     return (ERROR);
5918                     }
5919                 if (fromI >= 0 && toJ >= 0 && fromI < toJ)
5920                     everyK = tempInt;
5921                 else
5922                     {
5923                     MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
5924                     return (ERROR);
5925                     }
5926                 foundSlash = NO;
5927                 }
5928             else
5929                 {
5930                 if (fromI >= 0 && toJ < 0)
5931                     {
5932                     if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
5933                         return (ERROR);
5934                     fromI = tempInt;
5935                     }
5936                 else if (fromI < 0 && toJ < 0)
5937                     {
5938                     fromI = tempInt;
5939                     }
5940                 else if (fromI >= 0 && toJ >= 0 && everyK < 0)
5941                     {
5942                     if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
5943                         return (ERROR);
5944                     fromI = tempInt;
5945                     toJ = everyK = -1;
5946                     }
5947                 else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
5948                     {
5949                     if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
5950                         return (ERROR);
5951                     fromI = tempInt;
5952                     toJ = everyK = -1;
5953                     }
5954                 else
5955                     {
5956                     MrBayesPrint ("%s   Improperly formatted charset\n", spacer);
5957                         {
5958                         return (ERROR);
5959                         }
5960                     }
5961                 }
5962             
5963             expecting  = Expecting(ALPHA);
5964             expecting |= Expecting(NUMBER);
5965             expecting |= Expecting(SEMICOLON);
5966             expecting |= Expecting(DASH);
5967             expecting |= Expecting(BACKSLASH);
5968             expecting |= Expecting(COMMA);
5969             }
5970         }
5971     else if (expecting == Expecting(COMMA))
5972         {
5973         /* add set to tempSet */
5974         if (fromI >= 0)
5975             if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
5976                 return (ERROR);
5977
5978         fromI = toJ = everyK = -1;
5979         foundDash = foundSlash = NO;
5980         whichPartition++;
5981         if (whichPartition > numDivisions)
5982             {
5983             MrBayesPrint ("%s   Too many partitions of the data (expecting %d)\n", spacer, numDivisions);
5984             return (ERROR);
5985             }
5986         expecting  = Expecting(NUMBER);
5987         expecting |= Expecting(ALPHA);
5988         }
5989     else if (expecting == Expecting(COLON))
5990         {
5991         expecting  = Expecting(NUMBER);
5992         expecting |= Expecting(ALPHA);
5993         }
5994     else if (expecting == Expecting(DASH))
5995         {
5996         foundDash = YES;
5997         expecting = Expecting(NUMBER);
5998         }
5999     else if (expecting == Expecting(BACKSLASH))
6000         {
6001         foundSlash = YES;
6002         expecting = Expecting(NUMBER);
6003         }
6004     else
6005         return (ERROR);
6006
6007     return (NO_ERROR);
6008 }
6009
6010
6011 int DoRestore (void)
6012 {
6013     int         i, alreadyDone;
6014
6015     MrBayesPrint ("%s   Restore taxa\n", spacer);
6016
6017     /* add set to tempSet */
6018     if (fromI >= 0 && toJ < 0)
6019         {
6020         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6021             return (ERROR);
6022         }
6023     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
6024         {
6025         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6026             return (ERROR);
6027         }
6028     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
6029         {
6030         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6031             return (ERROR);
6032         }
6033         
6034     /* merge tempSet with excludedTaxa */
6035     alreadyDone = NO;
6036     for (i=0; i<numTaxa; i++)
6037         {
6038         if (tempSet[i] == 1)
6039             {
6040             if (taxaInfo[i].isDeleted == NO && alreadyDone == NO)
6041                 {
6042                 MrBayesPrint ("%s   Some taxa already included\n", spacer);
6043                 alreadyDone = YES;
6044                 }
6045             taxaInfo[i].isDeleted = NO;
6046             }
6047         }
6048
6049     SetLocalTaxa();
6050     if (SetUpAnalysis(&globalSeed) == ERROR)
6051         return ERROR;
6052
6053     /* show tempSet (for debugging) */
6054 #   if 0
6055     for (i=0; i<numTaxa; i++)
6056         MrBayesPrint ("%4d  %4d\n", i+1, tempSet[i]);
6057 #   endif
6058         
6059     return (NO_ERROR);
6060 }
6061
6062
6063 int DoRestoreParm (char *parmName, char *tkn)
6064 {
6065     int     i, index, tempInt;
6066         
6067     if (defMatrix == NO)
6068         {
6069         MrBayesPrint ("%s   A matrix must be specified before you can restore taxa\n", spacer);
6070         return (ERROR);
6071         }
6072         
6073     if (foundFirst == NO)
6074         {
6075         /* this is the first time in */
6076         fromI = toJ = everyK = -1;
6077         foundDash = NO;
6078         for (i=0; i<numTaxa; i++) /* clear tempSet */
6079             tempSet[i] = 0;
6080         foundFirst = YES;
6081         }
6082
6083     if (expecting == Expecting(ALPHA))
6084         {
6085         if (IsSame ("All", tkn) == SAME || IsSame ("All", tkn) == CONSISTENT_WITH)
6086             {
6087             for (i=0; i<numTaxa; i++)
6088                 tempSet[i] = 1;
6089             }
6090         else
6091             {
6092             if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
6093                 {
6094                 /* we are using a pre-defined taxa set */
6095                 if (numTaxaSets < 1)
6096                     {
6097                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
6098                     return (ERROR);
6099                     }
6100                 if (CheckString (taxaSetNames, numTaxaSets, tkn, &index) == ERROR)
6101                     {
6102                     MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
6103                     return (ERROR);
6104                     }
6105                 /* add taxa from taxset tkn to new tempSet */
6106                 for (i=0; i<numTaxa; i++)
6107                     {
6108                     if (IsBitSet (i, taxaSet[index]) == YES)
6109                         tempSet[i] = 1;
6110                     }
6111                 }
6112             else
6113                 {
6114                 /* we found the taxon name */
6115                 if (fromI >= 0 && toJ < 0)
6116                     {
6117                     if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6118                         return (ERROR);
6119                     }
6120                 else if (fromI >= 0 && toJ >= 0)
6121                     {
6122                     if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6123                         return (ERROR);
6124                     }
6125                 tempSet[index] = 1;
6126                 }
6127             fromI = toJ = everyK = -1;
6128             }
6129
6130         expecting  = Expecting(ALPHA);
6131         expecting |= Expecting(NUMBER);
6132         expecting |= Expecting(SEMICOLON);
6133         }
6134     else if (expecting == Expecting(NUMBER))
6135         {
6136         if (strlen(tkn) == 1 && !strcmp(tkn, "."))
6137             {
6138             tempInt = numTaxa;
6139             }
6140         else
6141             {
6142             sscanf (tkn, "%d", &tempInt);
6143             if (tempInt <= 0 || tempInt > numTaxa)
6144                 {
6145                 MrBayesPrint ("%s   Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa);
6146                 return (ERROR);
6147                 }
6148             }
6149         tempInt--;
6150         if (foundDash == YES)
6151             {
6152             if (fromI >= 0)
6153                 toJ = tempInt;
6154             else
6155                 {
6156                 MrBayesPrint ("%s   Improperly formatted restore set\n", spacer);
6157                 return (ERROR);
6158                 }
6159             foundDash = NO;
6160             }
6161         else
6162             {
6163             if (fromI >= 0 && toJ < 0)
6164                 {
6165                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6166                     return (ERROR);
6167                 fromI = tempInt;
6168                 }
6169             else if (fromI < 0 && toJ < 0)
6170                 {
6171                 fromI = tempInt;
6172                 }
6173             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
6174                 {
6175                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6176                     return (ERROR);
6177                 fromI = tempInt;
6178                 toJ = everyK = -1;
6179                 }
6180             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
6181                 {
6182                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
6183                     return (ERROR);
6184                 fromI = tempInt;
6185                 toJ = everyK = -1;
6186                 }
6187             else
6188                 {
6189                 MrBayesPrint ("%s   Improperly formatted restore set\n", spacer);
6190                     {
6191                     return (ERROR);
6192                     }
6193                 }
6194             }
6195         expecting  = Expecting(ALPHA);
6196         expecting |= Expecting(NUMBER);
6197         expecting |= Expecting(SEMICOLON);
6198         expecting |= Expecting(DASH);
6199         }
6200     else if (expecting == Expecting(DASH))
6201         {
6202         foundDash = YES;
6203         expecting = Expecting(NUMBER);
6204         }
6205     else
6206         return (ERROR);
6207
6208     return (NO_ERROR);
6209     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
6210 }
6211
6212
6213 int DoSet (void)
6214 {
6215     return (NO_ERROR);
6216 }
6217
6218
6219 int DoSetParm (char *parmName, char *tkn)
6220 {
6221     int         index;
6222     char        tempStr[100];
6223     int         tempI;
6224
6225     if (expecting == Expecting(PARAMETER))
6226         {
6227         expecting = Expecting(EQUALSIGN);
6228         }
6229     else
6230         {
6231         /* set Autoclose (autoClose) **********************************************************/
6232         if (!strcmp(parmName, "Autoclose"))
6233             {
6234             if (expecting == Expecting(EQUALSIGN))
6235                 expecting = Expecting(ALPHA);
6236             else if (expecting == Expecting(ALPHA))
6237                 {
6238                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6239                     {
6240                     if (!strcmp(tempStr, "Yes"))
6241                         autoClose = YES;
6242                     else
6243                         autoClose = NO;
6244                     }
6245                 else
6246                     {
6247                     MrBayesPrint ("%s   Invalid argument for autoclose\n", spacer);
6248                     return (ERROR);
6249                     }
6250                 if (autoClose == YES)
6251                     MrBayesPrint ("%s   Setting autoclose to yes\n", spacer);
6252                 else
6253                     MrBayesPrint ("%s   Setting autoclose to no\n", spacer);
6254                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6255                 }
6256             else
6257                 return (ERROR);
6258             }
6259         /* set Nowarnings (noWarn) **********************************************************/
6260         else if (!strcmp(parmName, "Nowarnings"))
6261             {
6262             if (expecting == Expecting(EQUALSIGN))
6263                 expecting = Expecting(ALPHA);
6264             else if (expecting == Expecting(ALPHA))
6265                 {
6266                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6267                     {
6268                     if (!strcmp(tempStr, "Yes"))
6269                         noWarn = YES;
6270                     else
6271                         noWarn = NO;
6272                     }
6273                 else
6274                     {
6275                     MrBayesPrint ("%s   Invalid argument for nowarnings\n", spacer);
6276                     return (ERROR);
6277                     }
6278                 if (noWarn == YES)
6279                     MrBayesPrint ("%s   Setting nowarnings to yes\n", spacer);
6280                 else
6281                     MrBayesPrint ("%s   Setting nowarnings to no\n", spacer);
6282                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6283                 }
6284             else
6285                 return (ERROR);
6286             }
6287         /* set Quitonerror (quitOnError) **************************************************/
6288         else if (!strcmp(parmName, "Quitonerror"))
6289             {
6290             if (expecting == Expecting(EQUALSIGN))
6291                 expecting = Expecting(ALPHA);
6292             else if (expecting == Expecting(ALPHA))
6293                 {
6294                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6295                     {
6296                     if (!strcmp(tempStr, "Yes"))
6297                         quitOnError = YES;
6298                     else
6299                         quitOnError = NO;
6300                     }
6301                 else
6302                     {
6303                     MrBayesPrint ("%s   Invalid argument for quitonerror\n", spacer);
6304                     return (ERROR);
6305                     }
6306                 if (quitOnError == YES)
6307                     MrBayesPrint ("%s   Setting quitonerror to yes\n", spacer);
6308                 else
6309                     MrBayesPrint ("%s   Setting quitonerror to no\n", spacer);
6310                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6311                 }
6312             else
6313                 return (ERROR);
6314             }
6315         /* set Autoreplace (autoOverwrite) **************************************************/
6316         else if (!strcmp(parmName, "Autoreplace"))
6317             {
6318             if (expecting == Expecting(EQUALSIGN))
6319                 expecting = Expecting(ALPHA);
6320             else if (expecting == Expecting(ALPHA))
6321                 {
6322                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6323                     {
6324                     if (!strcmp(tempStr, "Yes"))
6325                         {
6326                         autoOverwrite = YES;
6327                         MrBayesPrint ("%s   Setting autoreplace to yes\n", spacer);
6328                         }
6329                     else
6330                         {
6331                         autoOverwrite = NO;
6332                         MrBayesPrint ("%s   Setting autoreplace to no\n", spacer);
6333                         }
6334                     }
6335                 else
6336                     {
6337                     MrBayesPrint ("%s   Invalid argument for autoreplace\n", spacer);
6338                     return (ERROR);
6339                     }                   
6340                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6341                 }
6342             else
6343                 return (ERROR);
6344             }           
6345         /* set Scientific (scientific) *********************************************/
6346         else if (!strcmp(parmName, "Scientific"))
6347             {
6348             if (expecting == Expecting(EQUALSIGN))
6349                 expecting = Expecting(ALPHA);
6350             else if (expecting == Expecting(ALPHA))
6351                 {
6352                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6353                     {
6354                     if (!strcmp(tempStr, "Yes"))
6355                         scientific = YES;
6356                     else
6357                         scientific = NO;
6358                     }
6359                 else
6360                     {
6361                     MrBayesPrint ("%s   Invalid argument for Scientific\n", spacer);
6362                     return (ERROR);
6363                     }
6364                 if (scientific == YES)
6365                     MrBayesPrint ("%s   Setting Scientific to Yes\n", spacer);
6366                 else
6367                     MrBayesPrint ("%s   Setting Scientific to No\n", spacer);
6368                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6369                 }
6370             else
6371                 return (ERROR);
6372             }
6373         /* set Userlevel (userLevel) **********************************************************/
6374         else if (!strcmp(parmName, "Userlevel"))
6375             {
6376             if (expecting == Expecting(EQUALSIGN))
6377                 expecting = Expecting(ALPHA);
6378             else if (expecting == Expecting(ALPHA))
6379                 {
6380                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6381                     {
6382                     if (!strcmp(tempStr, "Standard"))
6383                         userLevel = STANDARD_USER;
6384                     else if (!strcmp (tempStr,"Developer"))
6385                         userLevel = DEVELOPER;
6386                     }
6387                 else
6388                     {
6389                     MrBayesPrint ("%s   Invalid argument for userlevel\n", spacer);
6390                     return (ERROR);
6391                     }
6392                 MrBayesPrint ("%s   Setting userlevel to %s\n", spacer, tempStr);
6393                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6394                     return ERROR;
6395                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6396                 }
6397             else
6398                 return (ERROR);
6399             }
6400         /* set Npthreads (number of pthreads) ****************************************************/
6401         else if (!strcmp(parmName, "Npthreads"))
6402             {
6403             if (expecting == Expecting(EQUALSIGN))
6404                 expecting = Expecting(NUMBER);
6405             else if (expecting == Expecting(NUMBER))
6406                 {
6407                 sscanf (tkn, "%d", &tempI);
6408                 nPThreads = tempI;
6409                 MrBayesPrint ("%s   Setting Npthreads to %d\n", spacer, nPThreads);
6410                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6411                 }
6412             else 
6413                 return (ERROR);
6414             }
6415         /* set Precision (number of decimals) ****************************************************/
6416         else if (!strcmp(parmName, "Precision"))
6417             {
6418             if (expecting == Expecting(EQUALSIGN))
6419                 expecting = Expecting(NUMBER);
6420             else if (expecting == Expecting(NUMBER))
6421                 {
6422                 sscanf (tkn, "%d", &tempI);
6423                 if (tempI < 3 || tempI > 15)
6424                     {
6425                     MrBayesPrint ("%s   Precision must be in the range 3 to 15\n", spacer);
6426                     return ERROR;
6427                     }
6428                 precision = tempI;
6429                 MrBayesPrint ("%s   Setting Precision to %d\n", spacer, precision);
6430                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6431                 }
6432             else 
6433                 return (ERROR);
6434             }
6435         /* set Partition (partitionNum) *******************************************************/
6436         else if (!strcmp(parmName, "Partition"))
6437             {
6438             if (defMatrix == NO)
6439                 {
6440                 MrBayesPrint ("%s   A character matrix must be defined first\n", spacer);
6441                 return (ERROR);
6442                 }
6443             if (expecting == Expecting(EQUALSIGN))
6444                 expecting = Expecting(ALPHA) | Expecting(NUMBER);
6445             else if (expecting == Expecting(ALPHA))
6446                 {
6447                 /* first check to see if name is there */
6448                 if (CheckString (partitionNames, numDefinedPartitions, tkn, &index) == ERROR)
6449                     {
6450                     MrBayesPrint ("%s   Could not find \"%s\" as a defined partition\n", spacer, tkn);
6451                     return (ERROR);
6452                     }
6453                 if (SetPartition (index) == ERROR)
6454                     return ERROR;
6455                 if (numCurrentDivisions == 1)
6456                     MrBayesPrint ("%s   Setting %s as the partition (does not divide up characters).\n", spacer, tkn); 
6457                 else
6458                     MrBayesPrint ("%s   Setting %s as the partition, dividing characters into %d parts.\n", spacer, tkn, numCurrentDivisions); 
6459                 if (SetModelDefaults () == ERROR)
6460                     return (ERROR);
6461                 if (SetUpAnalysis (&globalSeed) == ERROR)
6462                     return (ERROR);
6463                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6464                 }
6465             else if (expecting == Expecting(NUMBER))
6466                 {
6467                 sscanf (tkn, "%d", &index);
6468                 if (index > numDefinedPartitions) 
6469                     {
6470                     MrBayesPrint ("%s   Partition number %d is not a valid partition. Only %d partitions\n", spacer, index, numDefinedPartitions);
6471                     MrBayesPrint ("%s   have been defined.\n", spacer);
6472                     return (ERROR);
6473                     }
6474                 if (index < 1)
6475                     {
6476                     MrBayesPrint ("%s   Partition number %d is not a valid partition. Must be between 1 and %d.\n", spacer, index+1, numDefinedPartitions);
6477                     return (ERROR);
6478                     }
6479                 if (SetPartition (index) == ERROR)
6480                     return ERROR;
6481                 if (numCurrentDivisions == 1)
6482                     MrBayesPrint ("%s   Setting %s as the partition (does not divide up characters).\n", spacer, partitionNames[index]);
6483                 else
6484                     MrBayesPrint ("%s   Setting %s as the partition, dividing characters into %d parts.\n", spacer, partitionNames[index], numCurrentDivisions);
6485                 if (SetModelDefaults () == ERROR)
6486                     return (ERROR);
6487                 if (SetUpAnalysis (&globalSeed) == ERROR)
6488                     return (ERROR);
6489                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6490                 }
6491             else
6492                 return (ERROR);
6493             }
6494         /* set Speciespartition (speciespartitionNum) *******************************************************/
6495         else if (!strcmp(parmName, "Speciespartition"))
6496             {
6497             if (defTaxa == NO)
6498                 {
6499                 MrBayesPrint ("%s   A taxaset must be defined first\n", spacer);
6500                 return (ERROR);
6501                 }
6502             if (expecting == Expecting(EQUALSIGN))
6503                 expecting = Expecting(ALPHA) | Expecting(NUMBER);
6504             else if (expecting == Expecting(ALPHA))
6505                 {
6506                 /* first check to see if name is there */
6507                 if (CheckString (speciespartitionNames, numDefinedSpeciespartitions, tkn, &index) == ERROR)
6508                     {
6509                     MrBayesPrint ("%s   Could not find \"%s\" as a defined speciespartition\n", spacer, tkn);
6510                     return (ERROR);
6511                     }
6512                 if (SetSpeciespartition (index) == ERROR)
6513                     return ERROR;
6514                 MrBayesPrint ("%s   Setting %s as the speciespartition, dividing taxa into %d species.\n", spacer, tkn, numSpecies);
6515                 if (SetModelDefaults () == ERROR)
6516                     return (ERROR);
6517                 if (SetUpAnalysis (&globalSeed) == ERROR)
6518                     return (ERROR);
6519                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6520                 }
6521             else if (expecting == Expecting(NUMBER))
6522                 {
6523                 sscanf (tkn, "%d", &index);
6524                 if (index > numDefinedSpeciespartitions) 
6525                     {
6526                     MrBayesPrint ("%s   Speciespartition number %d is not valid. Only %d speciespartitions\n", spacer, index, numDefinedSpeciespartitions);
6527                     MrBayesPrint ("%s   have been defined.\n", spacer);
6528                     return (ERROR);
6529                     }
6530                 if (index < 1)
6531                     {
6532                     MrBayesPrint ("%s   Speciespartition number %d is not valid. Must be between 1 and %d.\n", spacer, index, numDefinedSpeciespartitions);
6533                     return (ERROR);
6534                     }
6535                 if (SetSpeciespartition (index-1) == ERROR)
6536                     return ERROR;
6537                 MrBayesPrint ("%s   Setting %s as the speciespartition, dividing taxa into %d species.\n", spacer, speciespartitionNames[index-1], numSpecies);
6538                 if (SetModelDefaults () == ERROR)
6539                     return (ERROR);
6540                 if (SetUpAnalysis (&globalSeed) == ERROR)
6541                     return (ERROR);
6542                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6543                 }
6544             else
6545                 return (ERROR);
6546             }
6547         /* set Seed (global variable globalSeed) ****************************************************/
6548         else if (!strcmp(parmName, "Seed"))
6549             {
6550             if (expecting == Expecting(EQUALSIGN))
6551                 expecting = Expecting(NUMBER);
6552             else if (expecting == Expecting(NUMBER))
6553                 {
6554                 sscanf (tkn, "%d", &tempI);
6555                 if (tempI == 0 || tempI == 2147483647)
6556                     {
6557                     MrBayesPrint ("%s   Error: Seed can be any natural number except 0 and 2147483647\n", spacer);
6558                     return (ERROR);
6559                     }
6560                 globalSeed = tempI;
6561                 MrBayesPrint ("%s   Setting seed to %ld\n", spacer, globalSeed);
6562                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6563                 }
6564             else 
6565                 return (ERROR);
6566             }
6567         /* set Swapseed (global variable swapSeed) ***************************************************************/
6568         else if (!strcmp(parmName, "Swapseed"))
6569             {
6570             if (expecting == Expecting(EQUALSIGN))
6571                 expecting = Expecting(NUMBER);
6572             else if (expecting == Expecting(NUMBER))
6573                 {
6574                 sscanf (tkn, "%d", &tempI);
6575                 if (tempI == 0 || tempI == 2147483647)
6576                     {
6577                     MrBayesPrint ("%s   Error: Swapseed can be any natural number except 0 and 2147483647\n", spacer);
6578                     return (ERROR);
6579                     }
6580                 swapSeed = tempI;
6581                 MrBayesPrint ("%s   Setting swapseed to %ld\n", spacer, swapSeed);
6582                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6583                 }
6584             else
6585                 return (ERROR);
6586             }
6587         /* set Dir (global variable workingDir) ***************************************************************/
6588         else if (!strcmp(parmName, "Dir"))
6589             {
6590             if (expecting == Expecting(EQUALSIGN))
6591                 {
6592                 expecting = Expecting(ALPHA);
6593                 readWord = YES;
6594                 }
6595             else if (expecting == Expecting(ALPHA))
6596                 {
6597                 if (strlen(tkn)>99)
6598                     {
6599                     MrBayesPrint ("%s   Maximum allowed length of working directory name is 99 characters. The given name:\n", spacer);
6600                     MrBayesPrint ("%s      '%s'\n", spacer,tkn);
6601                     MrBayesPrint ("%s   has %d characters.\n", spacer,strlen(tkn));
6602                     return (ERROR);
6603                     }
6604                 strcpy (workingDir, tkn);
6605 #   if defined (WIN_VERSION)
6606                 /* Reformat to Windows 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 #   else
6615                 /* Reformat to Unix with trailing '/' */
6616                 for (index=0; index<(int)strlen(workingDir); index++)
6617                     {
6618                     if (workingDir[index] == '\\')
6619                         workingDir[index] = '/';
6620                     }
6621                 if (strlen(workingDir) > 0 && workingDir[strlen(workingDir)-1] != '/')
6622                     strcat(workingDir,"/");
6623 #   endif
6624                 MrBayesPrint ("%s   Setting working directory to \"%s\"\n", spacer, workingDir);
6625                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6626                 }
6627             else
6628                 return (ERROR);
6629             }
6630         /* set Usebeagle (global variable BEAGLE usage) ***************************************************************/    
6631         else if (!strcmp(parmName, "Usebeagle"))
6632             {
6633             if (expecting == Expecting(EQUALSIGN))
6634                 expecting = Expecting(ALPHA);
6635             else if (expecting == Expecting(ALPHA))
6636                 {
6637 #   if defined (BEAGLE_ENABLED)
6638                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6639                     {
6640                     if (!strcmp(tempStr, "Yes"))
6641                         tryToUseBEAGLE = YES;
6642                     else
6643                         tryToUseBEAGLE = NO;
6644                     }
6645                 else
6646                     {
6647                     MrBayesPrint ("%s   Invalid argument for usebeagle\n", spacer);
6648                     return (ERROR);
6649                     }
6650                 if (tryToUseBEAGLE == YES)
6651                     MrBayesPrint ("%s   Setting usebeagle to yes\n", spacer);
6652                 else
6653                     MrBayesPrint ("%s   Setting usebeagle to no\n", spacer);
6654 #   else
6655                 BeagleNotLinked();
6656 #   endif
6657                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6658                     return ERROR;
6659                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6660                 }
6661             else
6662                 return (ERROR);
6663             }
6664         /* set Beagle resource number (global variable BEAGLE flag) ****************************************/
6665         else if (!strcmp(parmName, "Beagleresource"))
6666             {
6667             if (expecting == Expecting(EQUALSIGN))
6668                 expecting =  Expecting(NUMBER);
6669             else if (expecting == Expecting(NUMBER))
6670                 {
6671 #   if defined (BEAGLE_ENABLED)
6672                 sscanf (tkn, "%d", &tempI);
6673                 if (tempI < 0)
6674                     {
6675                     MrBayesPrint ("%s   Beagleresource must be a valid resource number or 99 to disable resource selection\n", spacer);
6676                     return ERROR;
6677                     }
6678                 beagleResourceNumber = tempI;
6679                 if (beagleResourceNumber == 99)
6680                     MrBayesPrint ("%s   Setting Beagleresource to %d (auto)\n", spacer, beagleResourceNumber);
6681                 else
6682                     MrBayesPrint ("%s   Setting Beagleresource to %d\n", spacer, beagleResourceNumber);
6683 #   else
6684                 BeagleNotLinked();
6685 #   endif
6686                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6687                     return ERROR;
6688                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6689                 }
6690             else
6691                 return (ERROR);
6692             }
6693         /* set Beagle resources requirements (global variable BEAGLE flag) ****************************************/
6694         else if (!strcmp(parmName, "Beagledevice"))
6695             {
6696             if (expecting == Expecting(EQUALSIGN))
6697                 expecting = Expecting(ALPHA);
6698             else if (expecting == Expecting(ALPHA))
6699                 {
6700 #   if defined (BEAGLE_ENABLED)
6701                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6702                     {
6703                     long oldFlags = beagleFlags;
6704                     if (!strcmp(tempStr, "Gpu"))
6705                         {
6706                         beagleFlags &= ~BEAGLE_FLAG_PROCESSOR_CPU;
6707                         beagleFlags |= BEAGLE_FLAG_PROCESSOR_GPU;
6708                         BeagleAddGPUDevicesToList(&beagleResource, &beagleResourceCount);                       
6709                         }
6710                     else
6711                         {  
6712                         beagleFlags &= ~BEAGLE_FLAG_PROCESSOR_GPU;
6713                         beagleFlags |= BEAGLE_FLAG_PROCESSOR_CPU;
6714                         BeagleRemoveGPUDevicesFromList(&beagleResource, &beagleResourceCount);
6715                         }
6716                     if (BeagleCheckFlagCompatability(beagleFlags) == NO) {
6717                         beagleFlags = oldFlags;
6718                         }
6719                     else {
6720                         if (beagleFlags & BEAGLE_FLAG_PROCESSOR_GPU)
6721                             MrBayesPrint ("%s   Setting beagledevice to GPU\n", spacer);
6722                         else
6723                             MrBayesPrint ("%s   Setting beagledevice to CPU\n", spacer);
6724                         }
6725                     }
6726                 else
6727                     {
6728                     MrBayesPrint ("%s   Invalid argument for beagledevice\n", spacer);
6729                     return (ERROR);
6730                     }
6731 #   else
6732                 BeagleNotLinked();
6733 #   endif
6734                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6735                     return ERROR;
6736                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6737                 }
6738             else
6739                 return (ERROR);
6740             }
6741         else if (!strcmp(parmName, "Beagleprecision"))
6742             {
6743             if (expecting == Expecting(EQUALSIGN))
6744                 expecting = Expecting(ALPHA);
6745             else if (expecting == Expecting(ALPHA))
6746                 {
6747 #   if defined (BEAGLE_ENABLED)
6748                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6749                     {
6750                     long oldFlags = beagleFlags;
6751                     if (!strcmp(tempStr, "Single"))
6752                         {
6753                         beagleFlags &= ~BEAGLE_FLAG_PRECISION_DOUBLE;
6754                         beagleFlags |= BEAGLE_FLAG_PRECISION_SINGLE;                       
6755                         }
6756                     else
6757                         {
6758                         beagleFlags &= ~BEAGLE_FLAG_PRECISION_SINGLE;
6759                         beagleFlags |= BEAGLE_FLAG_PRECISION_DOUBLE;
6760                         }
6761                     if (BeagleCheckFlagCompatability(beagleFlags) == NO) {
6762                         beagleFlags = oldFlags;
6763                         }
6764                     else {
6765                         if (beagleFlags & BEAGLE_FLAG_PRECISION_DOUBLE)
6766                             MrBayesPrint ("%s   Setting beagleprecision to double\n", spacer);
6767                         else
6768                             MrBayesPrint ("%s   Setting beagleprecision to single\n", spacer);
6769                         }
6770                     }
6771                 else
6772                     {
6773                     MrBayesPrint ("%s   Invalid argument for beagleprecision\n", spacer);
6774                     return (ERROR);
6775                     }
6776 #   else
6777                 BeagleNotLinked();
6778 #   endif
6779                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6780                     return ERROR;
6781                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6782                 }
6783             else
6784                 return (ERROR);
6785             }
6786         else if (!strcmp(parmName, "Beagleopenmp"))
6787             {
6788             if (expecting == Expecting(EQUALSIGN))
6789                 expecting = Expecting(ALPHA);
6790             else if (expecting == Expecting(ALPHA))
6791                 {
6792 #   if defined (BEAGLE_ENABLED)
6793                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6794                     {
6795                     long oldFlags = beagleFlags;
6796                     if (!strcmp(tempStr, "Yes"))
6797                         {
6798                         beagleFlags |= BEAGLE_FLAG_THREADING_OPENMP;
6799                         }
6800                     else
6801                         {
6802                         beagleFlags &= ~BEAGLE_FLAG_THREADING_OPENMP;                       
6803                         }
6804                     if (BeagleCheckFlagCompatability(beagleFlags) == NO) {
6805                         beagleFlags = oldFlags;
6806                         }
6807                     else {
6808                         if (beagleFlags & BEAGLE_FLAG_THREADING_OPENMP)
6809                             MrBayesPrint ("%s   Setting beagleopenmp to Yes\n", spacer);
6810                         else
6811                             MrBayesPrint ("%s   Setting beagleopenmp to No\n", spacer);
6812                         }
6813                     }
6814                 else
6815                     {
6816                     MrBayesPrint ("%s   Invalid argument for beagleopenmp\n", spacer);
6817                     return (ERROR);
6818                     }
6819 #   else
6820                 BeagleNotLinked();
6821 #   endif
6822                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6823                     return ERROR;
6824                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6825                 }
6826             else
6827                 return (ERROR);
6828             }
6829         else if (!strcmp(parmName, "Beaglefreq"))
6830             {
6831             if (expecting == Expecting(EQUALSIGN))
6832                 expecting = Expecting(NUMBER);
6833             else if (expecting == Expecting(NUMBER))
6834                 {
6835 #   if defined (BEAGLE_ENABLED)
6836                 sscanf (tkn, "%d", &tempI);
6837                 if (tempI < 0)
6838                     {
6839                     MrBayesPrint ("%s   Beaglefreq must be greater than 0\n", spacer);
6840                     return ERROR;
6841                     }
6842                 beagleScalingFrequency= tempI;
6843                 MrBayesPrint ("%s   Setting Beaglefreq to %d\n", spacer, beagleScalingFrequency);
6844 #   else
6845                 BeagleNotLinked();
6846 #   endif
6847                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6848                     return ERROR;
6849                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6850                 }
6851             else 
6852                 return (ERROR);
6853             }        
6854         else if (!strcmp(parmName, "Beaglesse"))
6855             {
6856             if (expecting == Expecting(EQUALSIGN))
6857                 expecting = Expecting(ALPHA);
6858             else if (expecting == Expecting(ALPHA))
6859                 {
6860 #   if defined (BEAGLE_ENABLED)
6861                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6862                     {
6863                     long oldFlags = beagleFlags;
6864                     if (!strcmp(tempStr, "Yes"))
6865                         {
6866                         beagleFlags |= BEAGLE_FLAG_VECTOR_SSE;
6867                         }
6868                     else
6869                         {
6870                         beagleFlags &= ~BEAGLE_FLAG_VECTOR_SSE;                     
6871                         }
6872                     if (BeagleCheckFlagCompatability(beagleFlags) == NO) {
6873                         beagleFlags = oldFlags;
6874                         }
6875                     else {
6876                         if (beagleFlags & BEAGLE_FLAG_VECTOR_SSE)
6877                             MrBayesPrint ("%s   Setting beaglesse to Yes\n", spacer);
6878                         else
6879                             MrBayesPrint ("%s   Setting beaglesse to No\n", spacer);
6880                         }
6881                     }
6882                 else
6883                     {
6884                     MrBayesPrint ("%s   Invalid argument for beagleopenmp\n", spacer);
6885                     return (ERROR);
6886                     }
6887 #   else
6888                 BeagleNotLinked();
6889 #   endif
6890                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6891                     return ERROR;
6892                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6893                 }
6894             else
6895                 return (ERROR);
6896             }
6897 #if 0
6898         else if (!strcmp(parmName, "Beaglevec"))
6899             {
6900             if (expecting == Expecting(EQUALSIGN))
6901                 expecting = Expecting(ALPHA);
6902             else if (expecting == Expecting(ALPHA))
6903                 {
6904 #   if defined (BEAGLE_ENABLED)
6905                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6906                     {                    
6907                     long oldFlags = beagleFlags;
6908                     if (!strcmp(tempStr, "Sse"))
6909                         {                      
6910                         beagleFlags |= BEAGLE_FLAG_VECTOR_SSE;
6911                         beagleFlags &= ~BEAGLE_FLAG_VECTOR_AVX;
6912                         }
6913                     else if (!strcmp(tempStr, "Avx"))
6914                         {  
6915                         beagleFlags |= ~BEAGLE_FLAG_VECTOR_AVX;
6916                         beagleFlags &= ~BEAGLE_FLAG_VECTOR_SSE;
6917                         }
6918                     else if (!strcmp(tempStr, "None"))
6919                         {
6920                         beagleFlags &= ~BEAGLE_FLAG_VECTOR_SSE;
6921                         beagleFlags &= ~BEAGLE_FLAG_VECTOR_AVX;
6922                         }
6923                     else
6924                         {
6925                         MrBayesPrint("%s   Unrecognized argument for beaglevec\n", spacer);
6926                         }
6927                     MrBayesPrint ("%s   Setting beaglevec to %s\n", spacer, tempStr);
6928                     }
6929                 else
6930                     {
6931                     MrBayesPrint ("%s   Invalid argument for beagleopenmp\n", spacer);
6932                     return (ERROR);
6933                     }
6934 #   else
6935                 BeagleNotLinked();
6936 #   endif
6937                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6938                     return ERROR;
6939                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6940                 }
6941             else
6942                 return (ERROR);
6943             }
6944 #endif
6945         else if (!strcmp(parmName, "Beaglethreads"))
6946             {
6947             if (expecting == Expecting(EQUALSIGN))
6948                 expecting = Expecting(ALPHA);
6949             else if (expecting == Expecting(ALPHA))
6950                 {
6951 #   if defined (BEAGLE_ENABLED) && defined (THREADS_ENABLED)
6952                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6953                     {
6954                     if (!strcmp(tempStr, "Yes"))
6955                         {
6956                         tryToUseThreads = YES;
6957                         }
6958                     else
6959                         {
6960                         tryToUseThreads = NO;                       
6961                         }
6962                     
6963                     if (tryToUseThreads == YES)
6964                         MrBayesPrint ("%s   Setting beaglethreads to Yes\n", spacer);
6965                     else
6966                         MrBayesPrint ("%s   Setting beaglethreads to No\n", spacer);                    
6967                     }
6968                 else
6969                     {
6970                     MrBayesPrint ("%s   Invalid argument for beaglethreads\n", spacer);
6971                     return (ERROR);
6972                     }
6973 #   else
6974                 BeagleThreadsNotLinked();
6975 #   endif
6976                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
6977                     return ERROR;
6978                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6979                 }
6980             }
6981         else if (!strcmp(parmName, "Beaglescaling"))
6982             {
6983             if (expecting == Expecting(EQUALSIGN))
6984                 expecting = Expecting(ALPHA);
6985             else if (expecting == Expecting(ALPHA))
6986                 {
6987 #   if defined (BEAGLE_ENABLED)
6988                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6989                     {
6990                     if (!strcmp(tempStr, "Always"))
6991                         {
6992                         beagleScalingScheme = MB_BEAGLE_SCALE_ALWAYS;
6993                         }
6994                     else
6995                         {
6996                         beagleScalingScheme = MB_BEAGLE_SCALE_DYNAMIC;                      
6997                         }
6998                     
6999                     if (beagleScalingScheme == MB_BEAGLE_SCALE_ALWAYS)
7000                         MrBayesPrint ("%s   Setting beaglescaling to Always\n", spacer);
7001                     else
7002                         MrBayesPrint ("%s   Setting beaglescaling to Dynamic\n", spacer);                    
7003                     }
7004                 else
7005                     {
7006                     MrBayesPrint ("%s   Invalid argument for beaglescaling\n", spacer);
7007                     return (ERROR);
7008                     }
7009 #   else
7010                 BeagleThreadsNotLinked();
7011 #   endif
7012                 if (defMatrix == YES && SetUpAnalysis(&globalSeed) == ERROR)
7013                     return ERROR;
7014                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7015                 }
7016             else
7017                 return (ERROR);
7018             }
7019         else
7020             return (ERROR);
7021         }
7022
7023     return (NO_ERROR);
7024 }
7025
7026
7027 int DoShowMatrix (void)
7028 {
7029     int         i, j, nameLen, start, finish, ct, longestName;
7030     char        tempStr[100], stride;
7031     
7032     if (defMatrix == NO)
7033         {
7034         MrBayesPrint ("%s   A character matrix must be defined first\n", spacer);
7035         return (ERROR);
7036         }
7037             
7038     longestName = 0;
7039     for (i=0; i<numTaxa; i++)
7040         {
7041         nameLen = (int) strlen(taxaNames[i]);
7042         if (nameLen > longestName)
7043             longestName = nameLen;
7044         }
7045             
7046     stride = 50;
7047     start = finish = 0;
7048     do
7049         {
7050         finish += stride;
7051         if (finish > numChar)
7052             finish = numChar;
7053
7054         MrBayesPrint ("%s   ", spacer);
7055         for (j=0; j<longestName; j++)
7056             MrBayesPrint (" ");
7057         MrBayesPrint ("  ");
7058         MrBayesPrint ("%d\n", start+1);
7059
7060         for (i=0; i<numTaxa; i++)
7061             {
7062             strcpy (tempStr, taxaNames[i]);
7063             nameLen = (int) strlen(tempStr);
7064             
7065             MrBayesPrint ("%s   ", spacer);
7066             if (nameLen >= longestName)
7067                 {
7068                 for (j=0; j<longestName; j++)
7069                     MrBayesPrint ("%c", tempStr[j]);
7070                 }
7071             else
7072                 {
7073                 MrBayesPrint ("%s", tempStr);
7074                 for (j=0; j<longestName-nameLen; j++)
7075                     MrBayesPrint (" ");
7076                 }
7077             MrBayesPrint ("  ");
7078
7079             for (j=start; j<finish; j++)
7080                 {
7081                 ct = charInfo[j].charType;
7082                 if (ct == DNA || ct == RNA)
7083                     MrBayesPrint ("%c", WhichNuc(matrix[pos(i,j,numChar)]));
7084                 else if (ct == PROTEIN)
7085                     MrBayesPrint ("%c", WhichAA(matrix[pos(i,j,numChar)]));
7086                 else if (ct == STANDARD)
7087                     MrBayesPrint ("%c", WhichStand(matrix[pos(i,j,numChar)]));
7088                 else if (ct == RESTRICTION)
7089                     MrBayesPrint ("%c", WhichRes(matrix[pos(i,j,numChar)]));
7090                 else if (ct == CONTINUOUS)
7091                     {
7092                     if (WhichCont(matrix[pos(i,j,numChar)]) < 0.0)
7093                         MrBayesPrint (" %2.2lf", WhichCont(matrix[pos(i,j,numChar)]));
7094                     else
7095                         MrBayesPrint ("  %2.2lf", WhichCont(matrix[pos(i,j,numChar)]));
7096                     }
7097                 else
7098                     {
7099                     MrBayesPrint ("%s   Unknown data type\n", spacer);
7100                     return (ERROR);
7101                     }
7102                 
7103                 }
7104             MrBayesPrint ("\n");
7105             }
7106         MrBayesPrint ("\n");
7107         start = finish;
7108         } while (finish != numChar);
7109
7110     return (NO_ERROR);
7111 }
7112
7113
7114 int DoShowUserTrees (void)
7115 {
7116     int         i;
7117
7118     if (numUserTrees == 0)
7119         {
7120         MrBayesPrint ("%s   No user trees have been defined\n", spacer);
7121         }
7122     else
7123         {
7124         for (i=0; i<numUserTrees; i++)
7125             {
7126             MrBayesPrint ("\n   Tree #%d -- '%s':\n\n", i+1, userTree[i]->name);
7127             ShowConTree (stdout, userTree[i], 70, NO);
7128             MrBayesPrint ("\n");
7129             }
7130         }
7131
7132     return (NO_ERROR);
7133 }
7134
7135
7136 int DoShowBeagle (void)
7137 {
7138 #   if defined (BEAGLE_ENABLED)
7139     BeaglePrintResources();
7140 #   else
7141     BeagleNotLinked();
7142 #   endif
7143     return (NO_ERROR);
7144 }
7145
7146
7147 int DoTaxlabels (void)
7148 {
7149     isTaxsetDef = YES;
7150
7151     /* add default speciespartition name to list of valid speciespartitions */
7152     if (AddString (&speciespartitionNames, 0, "Default") == ERROR)
7153         {
7154         MrBayesPrint ("%s   Problem adding Default speciespartition to list\n", spacer);
7155         return (ERROR);
7156         }
7157
7158     /* add default species name set */
7159     AddNameSet(&speciesNameSets, 0, taxaNames, numTaxa);
7160
7161     /* set number of defined speciespartitions to 1 */
7162     numDefinedSpeciespartitions = 1;
7163         
7164     return (NO_ERROR);
7165 }
7166
7167
7168 int DoTaxlabelsParm (char *parmName, char *tkn)
7169 {
7170     int         index;
7171
7172     if (inTaxaBlock == NO)
7173         {
7174         MrBayesPrint ("%s   You must be in a taxa block to read a taxlabels command\n", spacer);
7175         return (ERROR);
7176         }
7177
7178     if (defTaxa == NO)
7179         {
7180         MrBayesPrint ("%s   The number of taxa must be given before a set of taxon labels can be read\n", spacer);
7181         return ERROR;
7182         }
7183
7184     if (isTaxsetDef == YES)
7185         {
7186         MrBayesPrint ("%s   A set of taxon labels has already been defined\n", spacer);
7187         if (defMatrix == NO)
7188             if (WantTo ("Do you want to delete the current set of taxon labels") == NO)
7189                 return (SKIP_COMMAND);
7190             else
7191                 FreeTaxa();
7192         else
7193             if (WantTo ("Do you want to delete the current character matrix") == NO)
7194                 return (SKIP_COMMAND);
7195             else
7196                 FreeMatrix();
7197         }
7198
7199     if (expecting == Expecting(ALPHA) ||
7200         expecting == Expecting(NUMBER))
7201         {
7202         if (CheckString (taxaNames, numNamedTaxa, tkn, &index) == ERROR)
7203             {
7204             if (strlen(tkn)>99)
7205                 {
7206                 MrBayesPrint ("%s   Taxon name %s is too long. Maximun 99 characters is allowed.\n", spacer, tkn);
7207                 return (ERROR);
7208                 }
7209             if (AddString (&taxaNames, numNamedTaxa, tkn) == ERROR)
7210                 {
7211                 MrBayesPrint ("%s   Problem adding label %s to list of taxon labels\n", spacer, tkn);
7212                 return (ERROR);
7213                 }
7214             numNamedTaxa++;
7215             }
7216         else
7217             {
7218             MrBayesPrint ("%s   Taxon label '%s' is included twice in list of taxon labels\n", spacer, tkn);
7219             return (ERROR);
7220             }
7221         if (numNamedTaxa < numTaxa)
7222             {
7223             expecting = Expecting(ALPHA);
7224             expecting |= Expecting(NUMBER);
7225             }
7226         else
7227             expecting |= Expecting(SEMICOLON);
7228         }
7229
7230     return (NO_ERROR);
7231     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
7232     MrBayesPrint ("%s", tkn);
7233 }
7234
7235
7236 int DoSpeciespartition (void)
7237 {
7238     int     i, *partCount;
7239         
7240     /* add set to tempSet */
7241     if (fromI >= 0)
7242         if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
7243             {
7244             for (i=0; i<numDivisions; i++)
7245                 free(tempNames[i]);
7246             free (tempNames);
7247             tempNames = NULL;
7248             return (ERROR);
7249             }
7250
7251     /* set numDivisions; not set while reading the speciespartition */
7252     numDivisions = whichPartition + 1;
7253     
7254     /* check that all species are included */
7255     for (i=0; i<numTaxa; i++)
7256         {
7257         if (tempSet[i] == 0)
7258             {
7259             MrBayesPrint ("%s   Tip %d not included in speciespartition\n", spacer, i+1);
7260             for (i=0; i<numDivisions; i++)
7261                 free(tempNames[i]);
7262             free (tempNames);
7263             tempNames = NULL;
7264             return (ERROR);
7265             }
7266         /*MrBayesPrint ("%4d %4d \n", i, tempSet[i]);*/
7267         }
7268
7269     partCount = (int *) SafeCalloc (numDivisions, sizeof(int));
7270     if (!partCount)
7271         {
7272         for (i=0; i<numDivisions; i++)
7273             free(tempNames[i]);
7274         free (tempNames);
7275         tempNames = NULL;
7276         return ERROR;
7277         }
7278
7279     /* make certain that the partition labels go from 1 - numTaxa, inclusive */
7280     for (i=0; i<numTaxa; i++)
7281         {
7282         if (tempSet[i] < 1 || tempSet[i] > numTaxa)
7283             {
7284             MrBayesPrint ("%s   Speciespartition index for tip %d out of bound (%d)\n", spacer, i+1, tempSet[i]);
7285             free (partCount);
7286             for (i=0; i<numDivisions; i++)
7287                 free(tempNames[i]);
7288             free (tempNames);
7289             tempNames = NULL;
7290             return (ERROR);
7291             }
7292         partCount[tempSet[i] - 1]++;
7293         }
7294     for (i=0; i<numDivisions; i++)
7295         {
7296         if (partCount[i] == 0)
7297             {
7298             MrBayesPrint ("%s   Could not find a single tip for species %d\n", spacer, i+1);
7299             free (partCount);
7300             for (i=0; i<numDivisions; i++)
7301                 free(tempNames[i]);
7302             free (tempNames);
7303             tempNames = NULL;
7304             return (ERROR);
7305             }
7306         }
7307     free (partCount);
7308
7309     /* add name to list of valid partitions */
7310     if (AddString (&speciespartitionNames, numDefinedSpeciespartitions, tempSetName) == ERROR)
7311         {
7312         MrBayesPrint ("%s   Problem adding speciespartition %s to list\n", spacer, tempSetName);
7313         for (i=0; i<numDivisions; i++)
7314             free(tempNames[i]);
7315         free (tempNames);
7316         tempNames = NULL;
7317         return (ERROR);
7318         }
7319
7320     /* add new partition */
7321     for (i=0; i<numTaxa; i++)
7322         {
7323         speciespartitionId[i] = (int *) SafeRealloc ((void *)(speciespartitionId[i]), ((size_t)numDefinedSpeciespartitions + 1) * sizeof(int));
7324         if (!speciespartitionId[i])
7325             {
7326             for (i=0; i<numDivisions; i++)
7327                 free(tempNames[i]);
7328             free (tempNames);
7329             tempNames = NULL;
7330             return ERROR;
7331             }
7332         }
7333
7334     /* set new partition */
7335     for (i=0; i<numTaxa; i++)
7336         speciespartitionId[i][numDefinedSpeciespartitions] = tempSet[i];
7337
7338     /* add new set of species names */
7339     AddNameSet(&speciesNameSets, numDefinedSpeciespartitions, tempNames, numDivisions);
7340
7341     /* free species names */
7342     for (i=0; i<numDivisions; i++)
7343         free(tempNames[i]);
7344     free (tempNames);
7345     tempNames = NULL;
7346
7347     /* increment number of defined partitions */
7348     numDefinedSpeciespartitions++;
7349     
7350     return (NO_ERROR);
7351 }
7352
7353
7354 int DoSpeciespartitionParm (char *parmName, char *tkn)
7355 {
7356     int             i, index, tempInt;
7357     
7358     if (defTaxa == NO || numTaxa == 0)
7359         {
7360         MrBayesPrint ("%s   A matrix or taxaset must be specified before partitions can be defined\n", spacer);
7361         return (ERROR);
7362         }
7363
7364     if (expecting == Expecting(PARAMETER))
7365         {
7366         /* set Speciespartition name ******************************************************************/
7367         if (!strcmp(parmName, "Xxxxxxxxxx"))
7368             {
7369             /* check size of partition name */
7370             if (strlen(tkn) > 99)
7371                 {
7372                 MrBayesPrint ("%s   Partition name is too long. Max 100 characters\n", spacer);
7373                 return (ERROR);
7374                 }
7375                 
7376             /* check to see if the name has already been used as a partition */
7377             if (numDefinedSpeciespartitions > 0)
7378                 {
7379                 if (CheckString (speciespartitionNames, numDefinedSpeciespartitions, tkn, &index) == ERROR)
7380                     {
7381                     /* if the partition name has not been used, then we should have an ERROR returned */
7382                     /* we _want_ to be here */
7383
7384                     }
7385                 else
7386                     {
7387                     MrBayesPrint ("%s   Speciespartition name '%s' has been used previously\n", spacer, tkn);
7388                     return (ERROR);
7389                     }
7390                 }
7391                 
7392             /* add the name temporarily to tempSetName */
7393             strcpy (tempSetName, tkn);
7394             
7395             /* clear tempSet */
7396             for (i=0; i<numTaxa; i++)
7397                 tempSet[i] = 0;
7398     
7399             /* make sure tempNames is NULL */
7400             assert (tempNames == NULL);
7401
7402             fromI = toJ = everyK = -1;
7403             foundDash = foundSlash = NO;
7404             whichPartition = 0;
7405             foundFirst = NO;
7406             numDivisions = 0;
7407             MrBayesPrint ("%s   Defining speciespartition called '%s'\n", spacer, tkn);
7408             expecting = Expecting(EQUALSIGN);
7409             }
7410         else
7411             return (ERROR);
7412         }
7413     else if (expecting == Expecting(EQUALSIGN))
7414         {
7415         expecting = Expecting(ALPHA);
7416         }
7417     else if (expecting == Expecting(ALPHA))
7418         {
7419         if (foundFirst == NO)
7420             {
7421             AddString(&tempNames, whichPartition, tkn);
7422             foundFirst = YES;
7423             expecting = Expecting(COLON);
7424             }
7425         else
7426             {
7427             /* We are defining a species partition in terms of a tip name (called tkn, here). We should be able
7428                to find tkn in the list of tip names. If we cannot, then we have a problem and
7429                return an error. */
7430             if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
7431                 {
7432                 MrBayesPrint ("%s   Could not find a tip called '%s'\n", spacer, tkn);
7433                 return (ERROR);
7434                 }
7435             /* add index of the tip named tkn to new tempSet */
7436             tempSet[index] = whichPartition + 1;
7437             fromI = toJ = everyK = -1;
7438
7439             expecting  = Expecting(ALPHA);
7440             expecting |= Expecting(NUMBER);
7441             expecting |= Expecting(SEMICOLON);
7442             expecting |= Expecting(COMMA);
7443             }
7444         }
7445     else if (expecting == Expecting(NUMBER))
7446         {
7447         if (strlen(tkn) == 1 && tkn[0] == '.')
7448             tempInt = numTaxa;
7449         else
7450             sscanf (tkn, "%d", &tempInt);
7451         if (tempInt <= 0 || tempInt > numTaxa)
7452             {
7453             MrBayesPrint ("%s   Tip number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa);
7454             for (i=0; i<whichPartition; i++)
7455                 free(tempNames[i]);
7456             free (tempNames);
7457             tempNames = NULL;
7458             return (ERROR);
7459             }
7460         tempInt--;
7461         if (foundDash == YES)
7462             {
7463             if (fromI >= 0)
7464                 toJ = tempInt;
7465             else
7466                 {
7467                 MrBayesPrint ("%s   Improperly formatted speciespartition\n", spacer);
7468                 for (i=0; i<whichPartition; i++)
7469                     free(tempNames[i]);
7470                 free (tempNames);
7471                 tempNames = NULL;
7472                 return (ERROR);
7473                 }
7474             foundDash = NO;
7475             }
7476         else if (foundSlash == YES)
7477             {
7478             tempInt++;
7479             if (tempInt <= 1)
7480                 {
7481                 MrBayesPrint ("%s   Improperly formatted speciespartition\n", spacer);
7482                 for (i=0; i<whichPartition; i++)
7483                     free(tempNames[i]);
7484                 free (tempNames);
7485                 tempNames = NULL;
7486                 return (ERROR);
7487                 }
7488             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
7489                 everyK = tempInt;
7490             else
7491                 {
7492                 MrBayesPrint ("%s   Improperly formatted speciespartition\n", spacer);
7493                 for (i=0; i<whichPartition; i++)
7494                     free(tempNames[i]);
7495                 free (tempNames);
7496                 tempNames = NULL;
7497                 return (ERROR);
7498                 }
7499             foundSlash = NO;
7500             }
7501         else
7502             {
7503             if (fromI >= 0 && toJ < 0)
7504                 {
7505                 if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
7506                     {
7507                     for (i=0; i<whichPartition; i++)
7508                         free(tempNames[i]);
7509                     free (tempNames);
7510                     tempNames = NULL;
7511                     return (ERROR);
7512                     }
7513                 fromI = tempInt;
7514                 }
7515             else if (fromI < 0 && toJ < 0)
7516                 {
7517                 fromI = tempInt;
7518                 }
7519             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
7520                 {
7521                 if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
7522                     return (ERROR);
7523                 fromI = tempInt;
7524                 toJ = everyK = -1;
7525                 }
7526             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
7527                 {
7528                 if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
7529                     return (ERROR);
7530                 fromI = tempInt;
7531                 toJ = everyK = -1;
7532                 }
7533             else
7534                 {
7535                 MrBayesPrint ("%s   Improperly formatted speciespartition\n", spacer);
7536                     {
7537                     for (i=0; i<whichPartition; i++)
7538                         free(tempNames[i]);
7539                     free (tempNames);
7540                     tempNames = NULL;
7541                     return (ERROR);
7542                     }
7543                 }
7544             }
7545         expecting  = Expecting(ALPHA);
7546         expecting |= Expecting(NUMBER);
7547         expecting |= Expecting(SEMICOLON);
7548         expecting |= Expecting(DASH);
7549         expecting |= Expecting(BACKSLASH);
7550         expecting |= Expecting(COMMA);
7551         }
7552     else if (expecting == Expecting(COMMA))
7553         {
7554         /* add set to tempSet */
7555         if (fromI >= 0)
7556             if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR)
7557                 {
7558                 for (i=0; i<whichPartition; i++)
7559                     free(tempNames[i]);
7560                 free (tempNames);
7561                 tempNames = NULL;
7562                 return (ERROR);
7563                 }
7564
7565         fromI = toJ = everyK = -1;
7566         foundDash = foundSlash = foundFirst = NO;
7567         whichPartition++;
7568         if (whichPartition > numTaxa)
7569             {
7570             MrBayesPrint ("%s   Too many speciespartitions (expecting maximum %d speciespartitions)\n", spacer, numTaxa);
7571             for (i=0; i<whichPartition; i++)
7572                 free(tempNames[i]);
7573             free (tempNames);
7574             tempNames = NULL;
7575             return (ERROR);
7576             }
7577         expecting  = Expecting(ALPHA);
7578         }
7579     else if (expecting == Expecting(COLON))
7580         {
7581         expecting  = Expecting(NUMBER);
7582         expecting |= Expecting(ALPHA);
7583         }
7584     else if (expecting == Expecting(DASH))
7585         {
7586         foundDash = YES;
7587         expecting = Expecting(NUMBER);
7588         }
7589     else if (expecting == Expecting(BACKSLASH))
7590         {
7591         foundSlash = YES;
7592         expecting = Expecting(NUMBER);
7593         }
7594     else
7595         {
7596         for (i=0; i<whichPartition; i++)
7597             free(tempNames[i]);
7598         free (tempNames);
7599         tempNames = NULL;
7600         return (ERROR);
7601         }
7602
7603     return (NO_ERROR);
7604 }
7605
7606
7607 int DoTaxaset (void)
7608 {
7609     /* add set to tempSet */
7610     if (fromI >= 0 && toJ < 0)
7611         {
7612         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7613             return (ERROR);
7614         }
7615     else if (fromI >= 0 && toJ >= 0 && everyK < 0)
7616         {
7617         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7618             return (ERROR);
7619         }
7620     else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
7621         {
7622         if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7623             return (ERROR);
7624         }
7625         
7626     /* add name to taxaSetNames */
7627     if (AddString (&taxaSetNames, numTaxaSets, tempSetName) == ERROR)
7628         {
7629         MrBayesPrint ("%s   Problem adding taxset %s to list\n", spacer, tempSetName);
7630         return (ERROR);
7631         }
7632
7633     /* merge tempSet with taxaSet */
7634     AddBitfield (&taxaSet, numTaxaSets, tempSet, numTaxa);
7635     
7636     /* increment number of char sets */
7637     numTaxaSets++;
7638     
7639     /* show taxset (for debugging) */
7640 #   if 0
7641     for (i=0; i<numTaxa; i++)
7642         MrBayesPrint ("%4d  %4d\n", i+1, tempSet[i]);
7643 #   endif
7644
7645     return (NO_ERROR);
7646 }
7647
7648
7649 int DoTaxasetParm (char *parmName, char *tkn)
7650 {
7651     int     i, index, tempInt;
7652     
7653     if (defMatrix == NO)
7654         {
7655         MrBayesPrint ("%s   A matrix must be specified before taxsets can be defined\n", spacer);
7656         return (ERROR);
7657         }
7658
7659     if (expecting == Expecting(PARAMETER))
7660         {
7661         if (!strcmp(parmName, "Xxxxxxxxxx"))
7662             {
7663             /* check size of taxset name */
7664             if (strlen(tkn) > 99)
7665                 {
7666                 MrBayesPrint ("%s   Taxset name is too long\n", spacer);
7667                 return (ERROR);
7668                 }
7669                 
7670             /* check to see if the name has already been used as a taxset */
7671             if (numTaxaSets > 0)
7672                 {
7673                 if (CheckString (taxaSetNames, numTaxaSets, tkn, &index) == ERROR)
7674                     {
7675                     /* if the taxset name has not been used, then we should have an ERROR returned */
7676                     /* we _want_ to be here */
7677
7678                     }
7679                 else
7680                     {
7681                     MrBayesPrint ("%s   Taxset name has been used previously\n", spacer);
7682                     return (ERROR);
7683                     }
7684                 }
7685             else if (numTaxaSets > 30)
7686                 {
7687                 MrBayesPrint ("%s   You cannot define more than 30 taxsets\n", spacer);
7688                 return (ERROR);
7689                 }
7690                 
7691             /* add the name to the taxa set */
7692             strcpy (tempSetName, tkn);
7693             
7694             /* clear tempSet */
7695             for (i=0; i<numTaxa; i++)
7696                 tempSet[i] = 0;
7697             
7698             fromI = toJ = everyK = -1;
7699             foundDash = foundSlash = NO;
7700             MrBayesPrint ("%s   Defining taxset called '%s'\n", spacer, tkn);
7701             expecting = Expecting(EQUALSIGN);
7702             }
7703         else
7704             return (ERROR);
7705         }
7706     else if (expecting == Expecting(EQUALSIGN))
7707         {
7708         expecting  = Expecting(ALPHA);
7709         expecting |= Expecting(NUMBER);
7710         }
7711     else if (expecting == Expecting(ALPHA))
7712         {
7713         /* We are defining a taxon set in terms of another (called tkn, here) or we are referring to
7714            the taxon name. We should be able to find tkn in the list of character set names or in the list
7715            of taxon names. If we cannot, then we have a problem and return an error. */
7716         if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
7717             {
7718             if (numTaxaSets < 1)
7719                 {
7720                 MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
7721                 return (ERROR);
7722                 }
7723             if (CheckString (taxaSetNames, numTaxaSets, tkn, &index) == ERROR)
7724                 {
7725                 MrBayesPrint ("%s   Could not find a taxset called '%s'\n", spacer, tkn);
7726                 return (ERROR);
7727                 }
7728             /* add taxa from taxset tkn to new tempSet */
7729             for (i=0; i<numTaxa; i++)
7730                 {
7731                 if (IsBitSet (i, taxaSet[index]) == YES)
7732                     tempSet[i] = 1;
7733                 }
7734             }
7735         else
7736             {
7737             tempSet[index] = 1;
7738             }
7739         fromI = toJ = everyK = -1;
7740
7741         expecting  = Expecting(ALPHA);
7742         expecting |= Expecting(NUMBER);
7743         expecting |= Expecting(SEMICOLON);
7744         }
7745     else if (expecting == Expecting(NUMBER))
7746         {
7747         if (strlen(tkn) == 1 && !strcmp(tkn, "."))
7748             {
7749             tempInt = numTaxa;
7750             }
7751         else
7752             {
7753             sscanf (tkn, "%d", &tempInt);
7754             if (tempInt <= 0 || tempInt > numTaxa)
7755                 {
7756                 MrBayesPrint ("%s   Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa);
7757                 return (ERROR);
7758                 }
7759             }
7760         tempInt--;
7761         if (foundDash == YES)
7762             {
7763             if (fromI >= 0)
7764                 toJ = tempInt;
7765             else
7766                 {
7767                 MrBayesPrint ("%s   Improperly formatted taxset\n", spacer);
7768                 return (ERROR);
7769                 }
7770             foundDash = NO;
7771             }
7772         else if (foundSlash == YES)
7773             {
7774             tempInt++;
7775             if (tempInt <= 1)
7776                 {
7777                 MrBayesPrint ("%s   Improperly formatted taxset\n", spacer);
7778                 return (ERROR);
7779                 }
7780             if (fromI >= 0 && toJ >= 0 && fromI < toJ)
7781                 everyK = tempInt;
7782             else
7783                 {
7784                 MrBayesPrint ("%s   Improperly formatted taxset\n", spacer);
7785                 return (ERROR);
7786                 }
7787             foundSlash = NO;
7788             }
7789         else
7790             {
7791             if (fromI >= 0 && toJ < 0)
7792                 {
7793                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7794                     return (ERROR);
7795                 fromI = tempInt;
7796                 }
7797             else if (fromI < 0 && toJ < 0)
7798                 {
7799                 fromI = tempInt;
7800                 }
7801             else if (fromI >= 0 && toJ >= 0 && everyK < 0)
7802                 {
7803                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7804                     return (ERROR);
7805                 fromI = tempInt;
7806                 toJ = everyK = -1;
7807                 }
7808             else if (fromI >= 0 && toJ >= 0 && everyK >= 0)
7809                 {
7810                 if (AddToSet (fromI, toJ, everyK, 1) == ERROR)
7811                     return (ERROR);
7812                 fromI = tempInt;
7813                 toJ = everyK = -1;
7814                 }
7815             else
7816                 {
7817                 MrBayesPrint ("%s   Improperly formatted taxset\n", spacer);
7818                     {
7819                     return (ERROR);
7820                     }
7821                 }
7822             }
7823         
7824         expecting  = Expecting(ALPHA);
7825         expecting |= Expecting(NUMBER);
7826         expecting |= Expecting(SEMICOLON);
7827         expecting |= Expecting(DASH);
7828         expecting |= Expecting(BACKSLASH);
7829         }
7830     else if (expecting == Expecting(DASH))
7831         {
7832         foundDash = YES;
7833         expecting = Expecting(NUMBER);
7834         }
7835     else if (expecting == Expecting(BACKSLASH))
7836         {
7837         foundSlash = YES;
7838         expecting = Expecting(NUMBER);
7839         }
7840     else
7841         return (ERROR);
7842
7843     return (NO_ERROR);
7844 }
7845
7846
7847 int DoTaxaStat (void)
7848 {
7849     int         i, j, maxLen, nameLen, nIncludedTaxa;
7850     char        tempName[100];
7851     
7852     if (defMatrix == NO)
7853         {
7854         MrBayesPrint ("%s   A character matrix must be defined first\n", spacer);
7855         return (ERROR);
7856         }
7857         
7858     /* find maximum length of taxon name */
7859     maxLen = nIncludedTaxa = 0;
7860     for (i=0; i<numTaxa; i++)
7861         {
7862         strcpy (tempName, taxaNames[i]);
7863         if ((int)strlen(tempName) > maxLen)
7864             maxLen = (int) strlen(tempName);
7865         if (taxaInfo[i].isDeleted == NO)
7866             nIncludedTaxa++;
7867         }
7868             
7869     MrBayesPrint ("%s   Showing taxon status:\n\n", spacer);
7870     if (nIncludedTaxa == numTaxa)
7871         MrBayesPrint ("%s     Number of taxa        = %d (all of which are included)\n", spacer, numTaxa);
7872     else
7873         MrBayesPrint ("%s     Number of taxa        = %d (of which %d are included)\n", spacer, numTaxa, nIncludedTaxa);
7874     MrBayesPrint ("%s     Number of constraints = %d\n\n", spacer, numDefinedConstraints);
7875     
7876     if (numDefinedConstraints > 0)
7877         {
7878         for (j=0; j<numDefinedConstraints; j++)
7879             {
7880             strcpy (tempName, constraintNames[j]);
7881
7882             /* for now, ignore the probability */
7883             if (definedConstraintsType[j] == HARD)
7884                 MrBayesPrint ("%s     %2d -- Trees with 'hard' constraint \"%s\" are infinitely\n", spacer, j+1, tempName);
7885             else if (definedConstraintsType[j] == PARTIAL)
7886                 MrBayesPrint ("%s     %2d -- Trees with 'partial' constraint \"%s\" are infinitely\n", spacer, j+1, tempName);
7887             else
7888                 MrBayesPrint ("%s     %2d -- Trees with 'negative' constraint \"%s\" are infinitely\n", spacer, j+1, tempName);
7889             MrBayesPrint ("%s           more probable than those without \n", spacer);
7890             }
7891         MrBayesPrint ("\n");
7892         for (j=0; j<maxLen; j++)
7893             MrBayesPrint (" ");
7894         MrBayesPrint ("                             Constraints\n");
7895         }
7896     MrBayesPrint ("%s     Taxon  ", spacer);
7897     for (j=0; j<maxLen; j++)
7898         MrBayesPrint (" ");
7899     MrBayesPrint ("   Inclusion");
7900     MrBayesPrint ("   ");
7901     for (j=0; j<numDefinedConstraints; j++)
7902         MrBayesPrint (" %2d", j+1);
7903     MrBayesPrint ("\n");
7904     MrBayesPrint ("%s   -------", spacer);
7905     for (j=0; j<maxLen; j++)
7906         MrBayesPrint ("-");
7907     MrBayesPrint ("--------------");
7908     
7909     if (numDefinedConstraints > 0)
7910         {
7911         MrBayesPrint ("----");
7912         for (j=0; j<numDefinedConstraints; j++)
7913             MrBayesPrint ("---");
7914         }
7915     MrBayesPrint ("\n");
7916     for (i=0; i<numTaxa; i++)
7917         {
7918         strcpy (tempName, taxaNames[i]);
7919         nameLen = (int) strlen(tempName);
7920         
7921         if (i == outGroupNum)
7922             MrBayesPrint ("%s ->%4d (%s) ", spacer, i+1, tempName);
7923         else
7924             MrBayesPrint ("%s   %4d (%s) ", spacer, i+1, tempName);
7925         for (j=0; j<(maxLen-nameLen); j++)
7926             MrBayesPrint (" ");
7927         MrBayesPrint (" -- ");
7928         
7929         if (taxaInfo[i].isDeleted == YES)
7930             MrBayesPrint ("Deleted ");
7931         else
7932             MrBayesPrint ("Included");
7933             
7934         MrBayesPrint ("    ");
7935             
7936         for (j=0; j<numDefinedConstraints; j++)
7937             {
7938             if (definedConstraintsType[j] == HARD)
7939                 {
7940                 if (IsBitSet(i, definedConstraint[j]) == NO)
7941                     MrBayesPrint ("  .");
7942                 else
7943                     MrBayesPrint ("  *");
7944                 }
7945             else if (definedConstraintsType[j] == PARTIAL)
7946                 {
7947                 if (IsBitSet(i, definedConstraint[j]) == YES)
7948                     MrBayesPrint ("  +");
7949                 else if (IsBitSet(i, definedConstraintTwo[j]) == YES)
7950                     MrBayesPrint ("  -");
7951                 else
7952                     MrBayesPrint ("  .");
7953                 }
7954             else if (definedConstraintsType[j] == NEGATIVE)
7955                 {
7956                 if (IsBitSet(i, definedConstraint[j]) == NO)
7957                     MrBayesPrint ("  .");
7958                 else
7959                     MrBayesPrint ("  #");
7960                 }
7961             }
7962         MrBayesPrint ("\n");
7963         }
7964         
7965     MrBayesPrint ("\n");
7966     MrBayesPrint ("%s   '.' indicate that the taxon is not present in the constraint. \n", spacer);
7967     MrBayesPrint ("%s   '*' indicate that the taxon is present in the 'hard' constraint. \n", spacer);
7968     MrBayesPrint ("%s   '+' indicate that the taxon is present in the first groupe of 'partial' constraint. \n", spacer);
7969     MrBayesPrint ("%s   '-' indicate that the taxon is present in the second groupe of 'partial' constraint. \n", spacer);
7970     MrBayesPrint ("%s   '#' indicate that the taxon is present in the 'negative' constraint. \n", spacer);
7971     MrBayesPrint ("%s   Arrow indicates current outgroup. \n", spacer);
7972
7973     return (NO_ERROR);
7974 }
7975
7976
7977 int DoTranslate (void)
7978 {
7979     int     i, j;
7980
7981     if (inTreesBlock == NO)
7982         {
7983         MrBayesPrint ("%s   You must be in a trees block to read a translate command\n", spacer);
7984         return (ERROR);
7985         }
7986     numTranslates++;    /* number of taxa in translate table */
7987     isTranslateDef = YES;
7988
7989     isTranslateDiff = NO;
7990     if (isTaxsetDef == NO)
7991         SetTaxaFromTranslateTable();
7992     else
7993         {
7994         for (i=0; i<numTranslates; i++)
7995             {
7996             strcpy (token, transFrom[i]);
7997             if (CheckString (taxaNames, numTaxa, token, &j) == ERROR)
7998                 {
7999                 isTranslateDiff = YES;
8000                 }
8001             }
8002         if (numTranslates != numTaxa)
8003             isTranslateDiff = YES;
8004         }
8005
8006     return (NO_ERROR);
8007 }
8008
8009
8010 int DoTranslateParm (char *parmName, char *tkn)
8011 {
8012     int         index;
8013     static int  whichTranslate;
8014
8015     if (inTreesBlock == NO)
8016         {
8017         MrBayesPrint ("%s   You must be in a trees block to read a translate command\n", spacer);
8018         return (ERROR);
8019         }
8020
8021     if (isTranslateDef == YES)
8022         {
8023         MrBayesPrint ("%s   A translation has already been defined for this tree block\n", spacer);
8024         return (ERROR);
8025         }
8026         
8027     if (expecting == Expecting(ALPHA) ||
8028         expecting == Expecting(NUMBER))
8029         {
8030         if (numTaxa == 0)
8031             {
8032             MrBayesPrint ("%s   Data matrix should be defined before translation table could be set.\n", spacer);
8033             return (ERROR);
8034             }
8035         if (numTranslates == numTaxa)
8036             {
8037             MrBayesPrint ("%s   Too many entries in translation table. Maximum number of taxon names to translate is %d\n", spacer,numTaxa);
8038             return (ERROR);
8039             }
8040         if (whichTranslate == 0)
8041             {
8042             if (CheckString (transTo, numTranslates, tkn, &index) == ERROR)
8043                 {
8044                 if (AddString (&transTo, numTranslates, tkn) == ERROR)
8045                     {
8046                     MrBayesPrint ("%s   Problem adding taxon %s to list\n", spacer, tkn);
8047                     return (ERROR);
8048                     }
8049                 }
8050             else
8051                 {
8052                 MrBayesPrint ("%s   Already found name (%s) in list\n", spacer, tkn);
8053                 return (ERROR);
8054                 }           
8055             whichTranslate++;
8056             expecting = Expecting(ALPHA);
8057             expecting |= Expecting(NUMBER);
8058             }
8059         else 
8060             {
8061             if (CheckString (transFrom, numTranslates, tkn, &index) == ERROR)
8062                 {
8063                 if (AddString (&transFrom, numTranslates, tkn) == ERROR)
8064                     {
8065                     MrBayesPrint ("%s   Problem adding taxon %s to list\n", spacer, tkn);
8066                     return (ERROR);
8067                     }
8068                 }
8069             else
8070                 {
8071                 MrBayesPrint ("%s   Already found name (%s) in list\n", spacer, tkn);
8072                 return (ERROR);
8073                 }           
8074             whichTranslate = 0;
8075             expecting = Expecting(COMMA);
8076             expecting |= Expecting(SEMICOLON);
8077             }
8078         }
8079     else if (expecting == Expecting(COMMA))
8080         {
8081         numTranslates++;
8082         expecting = Expecting(ALPHA);
8083         expecting |= Expecting(NUMBER);
8084         }
8085
8086     return (NO_ERROR);
8087     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
8088     MrBayesPrint ("%s", tkn);
8089 }
8090
8091
8092 int DoTree (void)
8093 {
8094     readComment = NO;
8095
8096     if (inSumtCommand == YES || inComparetreeCommand == YES)
8097         return (DoSumtTree ());
8098
8099     return (NO_ERROR);
8100 }
8101
8102
8103 int DoTreeParm (char *parmName, char *tkn)
8104 {
8105     int                 i, tempInt, index;
8106     MrBFlt              tempD;
8107     char                tempName[100];
8108     static BitsLong     lastExpecting; /* keep track of what we expected before a comment, in case we want to skip a comment */
8109     static char         *tempNameString=NULL; /* Contains multiple tokens which form name string of param set*/
8110     static int          foundAmpersand, foundColon, foundComment, foundE, foundB, foundN, foundFirst,
8111                         foundCurly, /* is set to YES when we are between two curly bracets ONLY while processing CppEvent name */
8112                         foundClockrate, 
8113                         foundName, /*is set to YES when param set name token is found and set to NO once full param set name is processed*/
8114                         eSetIndex, /* is set in the begining of reading CppEvent for a node/branch to the index of currently processed CppEvent set */
8115                         bSetIndex, eventIndex, treeIndex, nextIntNodeIndex;
8116     static PolyNode     *pp, *qq;
8117     static PolyTree     *t;
8118     
8119     /* This function will read in components of a tree description. We expect one of the following formats:
8120     
8121           tree <name> = [&R] <newick-description>;
8122           tree <name> = [&U] <newick-description>;
8123           tree <name> [&E CppEvents]  = [&R] [&clockrate = 1.23] ((1:0.021[&E CppEvents 2: (0.10 1.11,0.83 3.17)],...
8124           tree <name> [&B TK02Brlens] = [&R] [&clockrate = 1.23] ((1:0.021[&B TK02Brlens 0.019],...
8125           tree <name> [&B IgrBrlens]  = [&R] [&clockrate = 1.23] ((1:0.021[&B IgrBrlens 0.019],...
8126      
8127        Values will be stored in event sets that go with the tree and that are used to initialize the relaxed clock
8128        parameters before a run is started. Note that several sets of events can be stored with each tree.
8129     */
8130
8131     if (isTaxsetDef == NO)
8132         {
8133         MrBayesPrint ("%s   Taxon labels must be specified before a tree could be red in\n", spacer);
8134         return (ERROR);
8135         }
8136     if (inTreesBlock == NO)
8137         {
8138         MrBayesPrint ("%s   You must be in a trees block to read a tree\n", spacer);
8139         return (ERROR);
8140         }
8141     
8142     if (expecting == Expecting(PARAMETER))
8143         {
8144         /* this is the name of the tree */
8145         if (inSumtCommand==YES || inComparetreeCommand == YES)
8146             {
8147             /* we are reading in a tree to sumt or comparetree counters */
8148             t = sumtParams.tree;
8149             ResetPolyTree (t);
8150             }
8151         else
8152             {
8153             /* we are reading in a user tree */
8154             /* check if the tree exists */
8155             treeIndex = 0;
8156             for (i=0; i<numUserTrees; i++)
8157                 if (strcmp(tkn,userTree[i]->name) == 0)
8158                     break;
8159             treeIndex = i;
8160             if (treeIndex < numUserTrees)
8161                 {
8162                 MrBayesPrint ("%s   Overwriting tree '%s'.\n", spacer, userTree[treeIndex]);
8163                 FreePolyTree (userTree[treeIndex]);
8164                 }
8165             if ((userTree[treeIndex] = AllocatePolyTree (numTaxa)) == NULL)
8166                 return (ERROR);
8167             t = userTree[treeIndex];
8168             }
8169         strncpy (t->name, tkn, 99);
8170         foundColon = foundAmpersand = foundEqual = foundComment = NO;
8171         foundE = foundB = foundN = foundFirst = foundClockrate = foundName = NO;
8172         eSetIndex = bSetIndex = eventIndex = 0;
8173         nextAvailableNode = 0;
8174         if (isTranslateDef == YES && isTranslateDiff == YES)
8175             nextIntNodeIndex = numTranslates;
8176         else
8177             nextIntNodeIndex = numTaxa;
8178         pp = &t->nodes[nextAvailableNode++];
8179         t->root = pp;
8180         t->isRooted = NO;  /* expect unrooted tree */
8181         t->isClock = NO;   /* expect nonclock tree */
8182         t->isCalibrated = NO;  /* expect uncalibrated tree */
8183         t->isRelaxed = NO;    /* expect strict clock if clock tree */
8184         t->clockRate = 0.0;     /* expect no clock rate */
8185         t->popSizeSet = NO;     
8186         readComment = YES;
8187         expecting = Expecting(EQUALSIGN) | Expecting(LEFTCOMMENT);
8188         lastExpecting = expecting;
8189         }
8190     else if (expecting == Expecting(EQUALSIGN))
8191         {
8192         if (foundClockrate == YES)
8193             expecting = Expecting(NUMBER);
8194         else
8195             {
8196             for (i=0; i<numTaxa; i++)
8197                 tempSet[i] = NO;
8198             foundEqual = YES;
8199             expecting = Expecting(LEFTPAR) | Expecting(LEFTCOMMENT);
8200             lastExpecting = expecting;
8201             }
8202         }
8203     else if (expecting == Expecting(LEFTPAR))
8204         {
8205         if (foundE == YES)
8206             {
8207             expecting = Expecting(NUMBER);
8208             }
8209         else
8210             {
8211             if (nextAvailableNode >= 2*numTaxa)
8212                 {
8213                 MrBayesPrint ("%s   Too many nodes on tree '%s'\n", spacer, t->name);
8214                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8215                     FreePolyTree (userTree[treeIndex]);
8216                 return (ERROR);
8217                 }
8218             qq = &t->nodes[nextAvailableNode++];
8219             qq->anc = pp;
8220             pp->left = qq;
8221             pp->index = nextIntNodeIndex++;
8222             pp = qq;
8223             expecting = Expecting(LEFTPAR);
8224             expecting |= Expecting(ALPHA);
8225             expecting |= Expecting(NUMBER);
8226             expecting |= Expecting(LEFTCOMMENT);
8227             lastExpecting = expecting;
8228             }
8229         }
8230     else if (expecting == Expecting(ALPHA))
8231         {
8232         if (foundAmpersand == YES)
8233             {
8234             if (strcmp(tkn,"E") == 0)
8235                 {
8236                 foundE = YES;
8237                 expecting = Expecting(ALPHA);
8238                 }
8239             else if (strcmp(tkn,"B") == 0)
8240                 {
8241                 foundB = YES;
8242                 expecting = Expecting(ALPHA);
8243                 }
8244             else if (strcmp(tkn,"N") == 0)
8245                 {
8246                 foundN = YES;
8247                 expecting = Expecting(ALPHA);
8248                 }
8249             else if (strcmp(tkn, "R") == 0)
8250                 {
8251                 t->isRooted = YES;
8252                 t->isClock = YES;   /* assume clock if rooted */
8253                 expecting = Expecting(RIGHTCOMMENT);
8254                 }
8255             else if (strcmp(tkn, "U") == 0)
8256                 {
8257                 t->isRooted = NO;
8258                 expecting = Expecting(RIGHTCOMMENT);
8259                 }
8260             else if (strcmp(tkn, "clockrate") == 0)
8261                 {
8262                 t->isCalibrated = YES;
8263                 foundClockrate = YES;
8264                 expecting = Expecting(EQUALSIGN);
8265                 }
8266             else
8267                 {
8268                 inComment = YES;
8269                 numComments++;
8270                 expecting = lastExpecting;
8271                 }
8272             foundAmpersand = NO;
8273             }
8274         else if (foundName == YES && foundCurly == YES)
8275             {
8276             if (strcmp("all",tkn) == 0)
8277                 {
8278                 SafeStrcat (&tempNameString,tkn);
8279                 expecting = Expecting(RIGHTCURL);
8280                 }
8281             else
8282                 {
8283                 MrBayesPrint ("%s   Urecognized argument '%s'\n", spacer, tkn);
8284                 return (ERROR);
8285                 }
8286             }
8287         else if (foundE == YES) /* We have seen &E */
8288             {
8289             if (foundEqual == NO) /* We have not seen name before and we are in header */
8290                 {
8291                 t->nESets++;
8292                 t->isRelaxed = YES;
8293                 t->nEvents  = (int **) SafeRealloc ((void *)t->nEvents, t->nESets*sizeof(int *));
8294                 t->position = (MrBFlt ***) SafeRealloc ((void *)t->position, t->nESets*sizeof(MrBFlt **));
8295                 t->rateMult = (MrBFlt ***) SafeRealloc ((void *)t->rateMult, t->nESets*sizeof(MrBFlt **));
8296                 t->nEvents[t->nESets-1]  = (int *) SafeCalloc (2*(size_t)numTaxa, sizeof(int));
8297                 t->position[t->nESets-1] = (MrBFlt **) SafeCalloc (2*(size_t)numTaxa, sizeof(MrBFlt *));
8298                 t->rateMult[t->nESets-1] = (MrBFlt **) SafeCalloc (2*(size_t)numTaxa, sizeof(MrBFlt *));
8299                 t->eSetName = (char **) SafeRealloc ((void *)t->eSetName, t->nESets*sizeof(char **));
8300                 }
8301             SafeStrcpy (&tempNameString,tkn);
8302             foundName = YES;
8303             expecting = Expecting(LEFTCURL);
8304             if (foundEqual == YES)
8305                 expecting |= Expecting(NUMBER);
8306             else
8307                 expecting |= Expecting(RIGHTCOMMENT);
8308             }
8309         else if (foundB == YES)
8310             {
8311             if (foundEqual == NO)
8312                 {
8313                 t->nBSets++;
8314                 t->isRelaxed = YES;
8315                 t->effectiveBrLen = (MrBFlt **) SafeRealloc ((void *)t->effectiveBrLen, (size_t)(t->nBSets)*sizeof(MrBFlt *));
8316                 t->effectiveBrLen[t->nBSets-1] = (MrBFlt *) SafeCalloc (2*(size_t)numTaxa, sizeof(MrBFlt));
8317                 for (i=0; i<2*numTaxa; i++)
8318                     t->effectiveBrLen[t->nBSets-1][i] = 1.0;
8319                 t->bSetName = (char **) SafeRealloc ((void *)t->bSetName, (size_t)(t->nBSets)*sizeof(char *));
8320                 t->bSetName[t->nBSets-1] = (char *) SafeCalloc (strlen(tkn)+1, sizeof(char));
8321                 }
8322             SafeStrcpy (&tempNameString,tkn);
8323             foundName = YES;
8324             expecting = Expecting(LEFTCURL);
8325             if (foundEqual == YES)
8326                 expecting |= Expecting(NUMBER);
8327             else
8328                 expecting |= Expecting(RIGHTCOMMENT);
8329             }
8330         else if (foundN == YES)
8331             {
8332             if (foundEqual == NO)
8333                 {
8334                 if (t->popSizeSet == YES)
8335                     {
8336                     MrBayesPrint ("%s   Cannot hold more than one population size set\n", spacer);
8337                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8338                         FreePolyTree (userTree[treeIndex]);
8339                     return (ERROR);
8340                     }
8341                 t->popSizeSet = YES;
8342                 if (isTranslateDef == YES && isTranslateDiff == YES)
8343                     t->popSize = (MrBFlt *) SafeCalloc (2*numTranslates, sizeof(MrBFlt));
8344                 else
8345                     t->popSize = (MrBFlt *) SafeCalloc (2*numLocalTaxa, sizeof(MrBFlt));
8346                 }
8347             SafeStrcpy (&tempNameString,tkn);
8348             foundName = YES;
8349             expecting = Expecting(LEFTCURL);
8350             if (foundEqual == YES)
8351                 expecting |= Expecting(NUMBER);
8352             else
8353                 expecting |= Expecting(RIGHTCOMMENT);
8354             }
8355         else   /* taxon name */
8356             {
8357             if (isTranslateDef == YES)
8358                 {
8359                 /* we are using the translation table */
8360                 if (CheckString (transTo, numTranslates, tkn, &index) == ERROR)
8361                     {
8362                     MrBayesPrint ("%s   Could not find token '%s' in taxon translation table\n", spacer, tkn);
8363                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8364                         FreePolyTree (userTree[treeIndex]);
8365                     return (ERROR);
8366                     }
8367                 strcpy (tempName, transFrom[index]);
8368                 if (isTranslateDiff == NO && CheckString (taxaNames, numTaxa, tempName, &index) == ERROR)
8369                     {
8370                     MrBayesPrint ("%s   Could not find taxon '%s' in list of taxa\n", spacer, tkn);
8371                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8372                         FreePolyTree (userTree[treeIndex]);
8373                     return (ERROR);
8374                     }
8375                 if (tempSet[index] == YES)
8376                     {
8377                     MrBayesPrint ("%s   Taxon name '%s' already used in tree\n", spacer, tkn);
8378                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8379                         FreePolyTree (userTree[treeIndex]);
8380                     return (ERROR);
8381                     }
8382                 tempSet[index] = YES;
8383                 strcpy (pp->label, tempName);
8384                 pp->index = index;
8385                 }
8386             else
8387                 {
8388                 /* Check to see if the name is in the list of taxon names. */
8389                 if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
8390                     {
8391                     MrBayesPrint ("%s   Could not find taxon '%s' in list of taxa\n", spacer, tkn);
8392                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8393                         FreePolyTree (userTree[treeIndex]);
8394                     return (ERROR);
8395                     }
8396                 if (tempSet[index] == YES)
8397                     {
8398                     MrBayesPrint ("%s   Taxon name '%s' already used in tree\n", spacer, tkn);
8399                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8400                         FreePolyTree (userTree[treeIndex]);
8401                     return (ERROR);
8402                     }
8403                 tempSet[index] = YES;
8404                 strcpy (pp->label, tkn);
8405                 pp->index = index;
8406                 }
8407             expecting  = Expecting(COMMA);
8408             expecting |= Expecting(COLON);
8409             expecting |= Expecting(RIGHTPAR);
8410             }
8411         }
8412     else if (expecting == Expecting(RIGHTPAR))
8413         {
8414         if (foundE == YES)
8415             expecting = Expecting(RIGHTCOMMENT);
8416         else
8417             {
8418             if (pp->anc == NULL)
8419                 {
8420                 MrBayesPrint ("%s   Incorrect tree format: cannot go down\n", spacer);//, tkn
8421                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8422                     FreePolyTree (userTree[treeIndex]);
8423                 return (ERROR);
8424                 }
8425             if (pp->anc->left == pp)
8426                 {
8427                 MrBayesPrint ("%s   Incorrect tree format: all nodes except tips should have more then one child. Either a single\n", spacer);
8428                 MrBayesPrint ("%s   taxon is surrounded with brackets or there is a clade surrounded by double brackets.\n", spacer);
8429                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8430                     FreePolyTree (userTree[treeIndex]);
8431                 return (ERROR);
8432                 }
8433             pp = pp->anc;
8434             if (pp->anc == NULL)
8435                 {
8436                 /* finish up tree */
8437                 t->nNodes = nextAvailableNode;
8438                 t->nIntNodes = t->nNodes;
8439                 for (i=0; i<t->nNodes; i++)
8440                     {
8441                     if (t->nodes[i].left == NULL)
8442                         t->nIntNodes--;
8443                     }
8444                 GetPolyDownPass(t);
8445                 
8446                 /* check that number of taxa is correct */
8447                 if (t->isRooted == NO && t->nNodes-t->nIntNodes == t->nIntNodes + 1)
8448                     t->isRooted = YES;
8449                 if ((t->isRooted == YES && t->nNodes-t->nIntNodes != t->nIntNodes + 1) ||
8450                     (t->isRooted == NO  && t->nNodes-t->nIntNodes != t->nIntNodes + 2))
8451                     {
8452                     /* we are protected from adding too many taxa by taxon-matching code above */
8453                     if (t->isRooted == YES && t->nNodes-t->nIntNodes == t->nIntNodes + 2)
8454                         {
8455                         MrBayesPrint ("%s   The tree is declared as rooted (by comment [&R]) but\n", spacer);
8456                         MrBayesPrint ("%s   the given tree has unrooted structure.\n", spacer);
8457                         }
8458                     else
8459                         MrBayesPrint ("%s   Taxa missing in tree, or NOT a binary tree\n", spacer);
8460
8461                     return (ERROR);
8462                     }
8463
8464                 /* check other properties */
8465                 if (t->isClock == YES && t->isRooted == NO)
8466                     {
8467                     MrBayesPrint ("%s   Tree has clock rate but is not rooted\n", spacer);
8468                     return (ERROR);
8469                     /* Note: any deviation from an ultrametric tree must be assumed to be due to dated
8470                        tips at this point */
8471                     }
8472                 if (t->isRelaxed == YES && t->isClock == NO)
8473                     {
8474                     MrBayesPrint ("%s   Tree has relaxed clock rates but is not a clock tree\n", spacer);
8475                     return (ERROR);
8476                     }
8477                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8478                     {
8479                     if (treeIndex == numUserTrees)
8480                         numUserTrees++;
8481                     MrBayesPrint ("%s   Successfully read tree '%s'\n", spacer, userTree[treeIndex]->name);
8482                     }
8483                 if (t->popSize == NULL)
8484                     {
8485                     readComment = NO;
8486                     expecting = Expecting(SEMICOLON);
8487                     }
8488                 else
8489                     {
8490                     readComment = YES;
8491                     expecting = Expecting(LEFTCOMMENT);
8492                     lastExpecting = expecting;
8493                     }
8494                 }
8495             else
8496                 {
8497                 expecting = Expecting(COMMA);
8498                 expecting |= Expecting(COLON);
8499                 expecting |= Expecting(RIGHTPAR);
8500                 }
8501             }
8502         }
8503     else if (expecting == Expecting(COLON))
8504         {
8505         foundColon = YES;
8506         if (foundE == YES)
8507             expecting = Expecting(LEFTPAR);
8508         else
8509             expecting  = Expecting(NUMBER);
8510         expecting |= Expecting(LEFTCOMMENT);
8511         lastExpecting = expecting;
8512         }
8513     else if (expecting == Expecting(COMMA))
8514         {
8515         if (foundName == YES)
8516             {
8517             SafeStrcat (&tempNameString,",");
8518             expecting = Expecting(NUMBER);
8519             }
8520         else if (foundE == YES)
8521             {
8522             expecting = Expecting(NUMBER);
8523             }
8524         else
8525             {
8526             if (nextAvailableNode >= 2*numTaxa)
8527                 {
8528                 MrBayesPrint ("%s   Too many nodes on tree '%s'\n", spacer, t->name);
8529                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8530                     FreePolyTree (userTree[treeIndex]);
8531                 return (ERROR);
8532                 }
8533             qq = &t->nodes[nextAvailableNode++];
8534             pp->sib = qq;
8535             qq->anc = pp->anc;
8536             pp = qq;
8537             expecting = Expecting(LEFTPAR);
8538             expecting |= Expecting(ALPHA);
8539             expecting |= Expecting(NUMBER);
8540             expecting |= Expecting(LEFTCOMMENT);
8541             lastExpecting = expecting;
8542             }
8543         }
8544     else if (expecting == Expecting(NUMBER))
8545         {
8546         if (foundClockrate == YES)
8547             {
8548             sscanf (tkn, "%lf", &tempD);
8549             t->clockRate = tempD;
8550             foundClockrate = NO;
8551             expecting = Expecting(RIGHTCOMMENT);
8552             }
8553         else if (foundName == YES && foundCurly == YES)
8554             {
8555             /* still assembling name of a param set */
8556             SafeStrcat (&tempNameString,tkn);       
8557             expecting = Expecting(RIGHTCURL) | Expecting(COMMA);
8558             }
8559         else if (foundN == YES)
8560             {
8561             /* we only know now that name is complete if it does not have curlies in it */
8562             foundName = NO;
8563
8564             if (strcmp(tempNameString,t->popSizeSetName) != 0)
8565                 {
8566                 MrBayesPrint ("%s   Could not find population size set '%s'\n", spacer, tempNameString);
8567                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8568                     FreePolyTree (userTree[treeIndex]);
8569                 return (ERROR);
8570                 }
8571
8572             sscanf (tkn, "%lf", &tempD);
8573             t->popSize[pp->index] = tempD;
8574             foundN = NO;
8575             expecting = Expecting(RIGHTCOMMENT);
8576             }
8577         else if (foundB == YES)
8578             {
8579             /* we only know now that name is complete if it does not have curlies in it */
8580             foundName = NO;
8581
8582             /* find the right effective branch length set */
8583             for (i=0; i<t->nBSets; i++)
8584                 if (strcmp(t->bSetName[i],tempNameString) == 0)
8585                     break;
8586             if (i == t->nBSets)
8587                 {
8588                 MrBayesPrint ("%s   Could not find effective branch length set '%s'\n", spacer, tempNameString);
8589                 if (inSumtCommand == NO && inComparetreeCommand == NO)
8590                     FreePolyTree (userTree[treeIndex]);
8591                 return (ERROR);
8592                 }
8593             bSetIndex = i;
8594
8595             sscanf (tkn, "%lf", &tempD);
8596             t->effectiveBrLen[bSetIndex][pp->index] = tempD;
8597             foundB = NO;
8598             expecting = Expecting(RIGHTCOMMENT);
8599             }
8600         else if (foundE == YES)
8601             {
8602             if (foundColon == NO)
8603                 {
8604                 /* we only know now that name is complete if it does not have curlies in it */
8605                 foundName = NO;
8606
8607                 /* find the right event set */
8608                 for (i=0; i<t->nESets; i++)
8609                     if (strcmp(t->eSetName[i],tempNameString) == 0)
8610                         break;
8611                 if (i == t->nESets)
8612                     {
8613                     MrBayesPrint ("%s   Could not find event set '%s'\n", spacer, tempNameString);
8614                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8615                         FreePolyTree (userTree[treeIndex]);
8616                     return (ERROR);
8617                     }
8618                 eSetIndex = i;
8619
8620                 sscanf (tkn, "%d", &tempInt);
8621                 if (tempInt < 0)
8622                     {
8623                     MrBayesPrint ("%s   Wrong number of events (%d) for event set '%s'\n", spacer, tempInt, t->eSetName[eSetIndex]);
8624                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8625                         FreePolyTree (userTree[treeIndex]);
8626                     return (ERROR);
8627                     }
8628                 t->nEvents[eSetIndex][pp->index]  = tempInt;
8629                 if (tempInt > 0)
8630                     {
8631                     t->position[eSetIndex][pp->index] = (MrBFlt *) SafeCalloc (tempInt, sizeof(MrBFlt));
8632                     t->rateMult[eSetIndex][pp->index] = (MrBFlt *) SafeCalloc (tempInt, sizeof(MrBFlt));
8633                     expecting = Expecting (COLON);
8634                     if (inSumtCommand == YES || inComparetreeCommand == YES)
8635                         expecting |= Expecting (RIGHTCOMMENT);  /* we allow empty event specifications in sumt and comparetree */
8636                     }
8637                 else
8638                     expecting = Expecting (RIGHTCOMMENT);
8639                 eventIndex = 0;
8640                 }
8641             else if (foundFirst == NO)
8642                 {
8643                 /* processing the first number in the cpp event pair <position rate> */
8644                 sscanf (tkn, "%lf", &tempD);
8645                 t->position[eSetIndex][pp->index][eventIndex] = tempD;
8646                 expecting = Expecting(NUMBER);
8647                 foundFirst = YES;
8648                 }
8649             else
8650                 {
8651                 /* processing the second number in the cpp event pair <position rate> */
8652                 foundFirst = NO;
8653                 sscanf (tkn, "%lf", &tempD);
8654                 t->rateMult[eSetIndex][pp->index][eventIndex] = tempD;
8655                 eventIndex++;
8656                 if (eventIndex == t->nEvents[eSetIndex][pp->index])
8657                     {
8658                     expecting = Expecting(RIGHTPAR);
8659                     foundColon = NO;
8660                     }
8661                 else
8662                     expecting = Expecting(COMMA);
8663                 }
8664             }
8665         else if (foundColon == YES)
8666             {
8667             /* branch length */
8668             sscanf (tkn, "%lf", &tempD);
8669             pp->length = tempD;
8670             foundColon = NO;
8671             t->brlensDef = YES;
8672             expecting  = Expecting(COMMA);
8673             expecting |= Expecting(RIGHTPAR);
8674             expecting |= Expecting(LEFTCOMMENT);
8675             lastExpecting = expecting;
8676             }
8677         else    /* taxon identifier */
8678             {
8679             if (isTranslateDef == YES)
8680                 {
8681                 /* we are using the translation table */
8682                 if (CheckString (transTo, numTranslates, tkn, &index) == ERROR)
8683                     {
8684                     MrBayesPrint ("%s   Could not find token '%s' in taxon translation table\n", spacer, tkn);
8685                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8686                         FreePolyTree (userTree[treeIndex]);
8687                     return (ERROR);
8688                     }
8689                 strcpy (tempName, transFrom[index]);
8690                 if (isTranslateDiff == NO && CheckString (taxaNames, numTaxa, tempName, &index) == ERROR)
8691                     {
8692                     MrBayesPrint ("%s   Could not find taxon '%s' in list of taxa\n", spacer, tkn);
8693                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8694                         FreePolyTree (userTree[treeIndex]);
8695                     return (ERROR);
8696                     }
8697                 if (tempSet[index] == YES)
8698                     {
8699                     MrBayesPrint ("%s   Taxon name '%s' already used in tree\n", spacer, tkn);
8700                     if (inSumtCommand == NO && inComparetreeCommand == NO)
8701                         FreePolyTree (userTree[treeIndex]);
8702                     return (ERROR);
8703                     }
8704                 tempSet[index] = YES;
8705                 strcpy (pp->label, tempName);
8706                 pp->index = index;
8707                 }
8708             else
8709                 {
8710                 /* Simply use taxon number; first check to see if the name is in the list of taxon names. */
8711                 if (CheckString (taxaNames, numTaxa, tkn, &index) == ERROR)
8712                     {
8713                     /* The number could not be found as a taxon name in the list of taxon names. We will
8714                         assume that the user has then input taxa as numbers and not the names. */
8715                     sscanf (tkn, "%d", &index);
8716                     if (index < 1 || index > numTaxa)
8717                         {
8718                         MrBayesPrint ("%s   Taxon number %d is out of range\n", spacer, index);
8719                         if (inSumtCommand == NO && inComparetreeCommand == NO)
8720                             FreePolyTree (userTree[treeIndex]);
8721                         return (ERROR);
8722                         }
8723                     index--;
8724                     if (tempSet[index] == YES)
8725                         {
8726                         MrBayesPrint ("%s   Taxon name %d has already been used in tree '%s'\n", spacer, index+1, t->name);
8727                         if (inSumtCommand == NO && inComparetreeCommand == NO)
8728                             FreePolyTree (userTree[treeIndex]);
8729                         return (ERROR);
8730                         }
8731                     }
8732                 else
8733                     {
8734                     /* The number is in the list of taxon names */
8735                     if (index < 0 || index >= numTaxa)
8736                         {
8737                         MrBayesPrint ("%s   Taxon name %s could not be found\n", spacer, tkn);
8738                         if (inSumtCommand == NO && inComparetreeCommand == NO)
8739                             FreePolyTree (userTree[treeIndex]);
8740                         return (ERROR);
8741                         }
8742                     if (tempSet[index] == YES)
8743                         {
8744                         MrBayesPrint ("%s   Taxon %d has already been used in tree '%s'\n", spacer, index+1, t->name);
8745                         if (inSumtCommand == NO && inComparetreeCommand == NO)
8746                             FreePolyTree (userTree[treeIndex]);
8747                         return (ERROR);
8748                         }
8749                     }
8750                 tempSet[index] = YES;
8751                 strcpy (pp->label, taxaNames[index]);
8752                 pp->index = index;
8753                 }
8754             expecting  = Expecting(COMMA);
8755             expecting |= Expecting(COLON);
8756             expecting |= Expecting(RIGHTPAR);
8757             expecting |= Expecting(LEFTCOMMENT);
8758             lastExpecting = expecting;
8759             }
8760         }
8761     else if (expecting == Expecting(LEFTCOMMENT))
8762         {
8763         expecting = Expecting(AMPERSAND);
8764         foundComment = YES;
8765         }
8766     else if (expecting == Expecting(RIGHTCOMMENT))
8767         {
8768         if (foundEqual == NO)
8769             {
8770             /* We may have a complete name of a set of branch parameters, which needs to be recorded */
8771             if (foundName == YES)
8772                 {
8773                 if (foundE == YES)
8774                     {
8775                     t->eSetName[t->nESets-1] = (char *) SafeCalloc (strlen(tempNameString)+1,sizeof(char));
8776                     strcat(t->eSetName[t->nESets-1],tempNameString);
8777                     }
8778                 else if (foundB == YES)
8779                     {
8780                     t->bSetName[t->nBSets-1] = (char *) SafeCalloc (strlen(tempNameString)+1,sizeof(char));
8781                     strcat(t->bSetName[t->nBSets-1],tempNameString);
8782                     }
8783                 else if (foundN == YES)
8784                     {
8785                     t->popSizeSetName = (char *) SafeCalloc (strlen(tempNameString)+1,sizeof(char));
8786                     strcpy(t->popSizeSetName,tempNameString);
8787                     }
8788                 foundName = NO;
8789                 }
8790             expecting = Expecting(EQUALSIGN);
8791             }
8792         else
8793             {
8794             if (pp->anc == NULL)
8795                 {
8796                 if (pp->left == NULL)
8797                     expecting = Expecting(LEFTPAR);
8798                 else
8799                     expecting = Expecting(SEMICOLON);
8800                 }
8801             else if (pp == pp->anc->left)
8802                 expecting = Expecting(COMMA);
8803             else
8804                 expecting = Expecting(RIGHTPAR);
8805             }
8806         foundE = foundB = foundN = NO;
8807         expecting |= Expecting(LEFTCOMMENT);
8808         }
8809     else if (expecting == Expecting(AMPERSAND))
8810         {
8811         foundAmpersand = YES;
8812         foundComment = NO;
8813         expecting = Expecting (ALPHA);
8814         }
8815     else if (foundComment == YES)
8816         {
8817         numComments++;
8818         foundComment = NO;
8819         }
8820     else if (expecting == Expecting(LEFTCURL))
8821         {
8822         if (foundName == YES)
8823             {
8824             foundCurly=YES;
8825             SafeStrcat (&tempNameString,"{");               
8826             expecting = Expecting(NUMBER) | Expecting(ALPHA);
8827             }
8828         else
8829             return(ERROR);
8830         }
8831     else if (expecting == Expecting(RIGHTCURL))
8832         {
8833         if (foundName == YES)
8834             {
8835             SafeStrcat (&tempNameString,"}");
8836             foundCurly=NO;
8837             if (foundEqual == NO)
8838                 {
8839                 /* We are processing a name of a set of branch params in the header of a tree.  */
8840                 expecting = Expecting(RIGHTCOMMENT);
8841                 }
8842             else
8843                 {
8844                 /* We are processing a param value of a branch param set  */
8845                 expecting = Expecting(NUMBER);
8846                 }
8847             }
8848         else
8849             return(ERROR);
8850         }
8851
8852     return (NO_ERROR);
8853     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
8854 }
8855
8856
8857 int DoUserTree (void)
8858 {
8859     MrBayesPrint ("%s   Usertree command deprecated. Define the tree in a treeblock and use 'Startvals' instead.\n", spacer);
8860     return (ERROR);
8861 }
8862
8863
8864 int DoUserTreeParm (char *parmName, char *tkn)
8865 {
8866     if (expecting == Expecting(EQUALSIGN))
8867         {
8868         expecting = Expecting(LEFTPAR);
8869         expecting |= Expecting(RIGHTPAR);
8870         expecting |= Expecting(COLON);
8871         expecting |= Expecting(NUMBER);
8872         expecting |= Expecting(ALPHA);
8873         expecting |= Expecting(SEMICOLON);
8874         }
8875     else if (expecting == Expecting(LEFTPAR))
8876         {
8877         expecting = Expecting(LEFTPAR);
8878         expecting |= Expecting(ALPHA);
8879         expecting |= Expecting(NUMBER);
8880         }
8881     else if (expecting == Expecting(ALPHA))
8882         {
8883         expecting = Expecting(COLON);
8884         expecting |= Expecting(COMMA);
8885         expecting |= Expecting(RIGHTPAR);
8886         }
8887     else if (expecting == Expecting(NUMBER))
8888         {
8889         expecting = Expecting(COLON);
8890         expecting |= Expecting(COMMA);
8891         expecting |= Expecting(RIGHTPAR);
8892         }
8893     else if (expecting == Expecting(COLON))
8894         {
8895         expecting = Expecting(NUMBER);
8896         }
8897     else if (expecting == Expecting(COMMA))
8898         {
8899         expecting = Expecting(LEFTPAR);
8900         expecting |= Expecting(ALPHA);
8901         expecting |= Expecting(NUMBER);
8902         }
8903     else if (expecting == Expecting(RIGHTPAR))
8904         {
8905         expecting = Expecting(RIGHTPAR);
8906         expecting |= Expecting(COMMA);
8907         expecting |= Expecting(COLON);
8908         expecting |= Expecting(SEMICOLON);
8909         }
8910     else
8911         return (ERROR);
8912
8913     return (NO_ERROR);
8914     MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */
8915     MrBayesPrint ("%s", tkn);
8916 }
8917
8918
8919 int DoVersion (void)
8920 {
8921     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
8922     MrBayesPrint ("   Version                                                                       \n");
8923     MrBayesPrint ("                                                                                 \n");
8924     MrBayesPrint ("   MrBayes v%s                                                                   \n", VERSION_NUMBER);
8925     MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
8926
8927     return (NO_ERROR);
8928 }
8929
8930
8931 BitsLong Expecting (int y)
8932 {
8933     BitsLong x;
8934     
8935     x = (BitsLong) pow (2.0, (MrBFlt)y);
8936     
8937     return (x);
8938 }
8939
8940
8941 #ifdef HAVE_LIBREADLINE
8942 /* This function is for commandline substitution: first word is always a command */
8943 char *command_generator(const char *text, int state)
8944 {
8945     static int list_index, len;
8946     char *command;
8947
8948     if (state==0) 
8949         {
8950         list_index=0;
8951         len= (int) strlen(text);
8952         }
8953     while ((command=commands[list_index].string)!=NULL) 
8954         {
8955         list_index++;
8956         if (strncasecmp(command,text,len)==0) 
8957             /* memory is freed by the readline library so we need a strdup here */ 
8958             return strdup(command);
8959         }
8960     return (char *)NULL;
8961 }
8962 #endif
8963
8964
8965 int FindValidCommand (char *tk, int *numMatches)
8966 {
8967     int             i, j, tkLen, targetLen, numDiff;
8968     CmdType         *p;
8969
8970     p = commands + 0;
8971     tkLen = (int) strlen(tk);
8972
8973     (*numMatches) = 0;
8974     for (i=0; i<NUMCOMMANDS; i++)
8975         {
8976         targetLen = (int) strlen(p->string);
8977         if (tkLen <= targetLen)
8978             {
8979             for (j=0, numDiff=0; j<tkLen; j++)
8980                 {
8981                 if (ChangeCase(tk[j]) != ChangeCase(p->string[j]))
8982                     numDiff++;
8983                 }
8984             if (numDiff == 0)
8985                 {
8986                 (*numMatches)++;
8987                 commandPtr = p;
8988                 if (tkLen == targetLen)
8989                     break;
8990                 }
8991             }
8992         p++;
8993         }
8994
8995     inValidCommand = NO;
8996     if (*numMatches == 1)
8997         {
8998         inValidCommand = YES;
8999         return (NO_ERROR);
9000         }
9001     else
9002         return (ERROR);
9003 }
9004
9005
9006 int FindValidParam (char *tk, int *numMatches)
9007 {
9008     int         i, j, tkLen, targetLen, numDiff;
9009     CmdType     *p;
9010     ParmInfoPtr q;
9011
9012     if (commandPtr)
9013         p = commandPtr;
9014     else
9015         {
9016         MrBayesPrint ("%s   Command pointer is NULL\n", spacer);
9017         return (ERROR);
9018         }
9019     tkLen = (int) strlen(tk);
9020
9021     *numMatches = 0;
9022     for (i=0; i<p->numParms; i++)
9023         {
9024         q = paramTable + (p->parmList[i]);
9025         targetLen = (int) strlen(q->string);
9026         /* printf ("%s %d (%s %d)\n", q->string, targetLen, tk, p->numParms); */
9027         if (!strcmp(q->string, "Xxxxxxxxxx"))
9028             {
9029             (*numMatches)++;
9030             paramPtr = q;
9031             }
9032         else if (tkLen <= targetLen)
9033             {
9034             for (j=0, numDiff=0; j<tkLen; j++)
9035                 {
9036                 if (ChangeCase(tk[j]) != ChangeCase(q->string[j]))
9037                     numDiff++;
9038                 }
9039             if (numDiff == 0)
9040                 {
9041                 (*numMatches)++;
9042                 paramPtr = q;
9043                 if (tkLen == targetLen)
9044                     break;
9045                 }
9046             }   
9047         }
9048     
9049     if (*numMatches == 1)
9050         return (NO_ERROR);
9051     else
9052         return (ERROR);
9053 }
9054
9055
9056 int FreeCharacters (void)
9057 {
9058     int     i, memoryLetFree;
9059     
9060     memoryLetFree = NO;
9061
9062     if (memAllocs[ALLOC_TMPSET] == YES)
9063         {
9064         if (numChar > numTaxa)
9065             tempSet = (int *) SafeRealloc ((void *)tempSet, (size_t)numTaxa*sizeof(int));
9066             tempSetNeg = (int *) SafeRealloc ((void *)tempSetNeg, (size_t)numTaxa*sizeof(int));
9067         }
9068     if (memAllocs[ALLOC_MATRIX] == YES)
9069         {
9070         free (matrix);
9071         matrix = NULL;
9072         defMatrix = NO;
9073         memAllocs[ALLOC_MATRIX] = NO;
9074         memoryLetFree = YES;
9075         }
9076     if (memAllocs[ALLOC_CHARINFO] == YES)
9077         {
9078         free (charInfo);
9079         charInfo = NULL;
9080         memAllocs[ALLOC_CHARINFO] = NO;
9081         memoryLetFree = YES;
9082         }
9083     if (memAllocs[ALLOC_CHARSETS] == YES)
9084         {
9085         for (i=0; i<numCharSets; i++)
9086             {
9087             free (charSetNames[i]);
9088             free (charSet[i]);
9089             }
9090         free (charSetNames);
9091         free (charSet);
9092         charSetNames = NULL;
9093         charSet = NULL;
9094         numCharSets = 0;
9095         memAllocs[ALLOC_CHARSETS] = NO;
9096         memoryLetFree = YES;
9097         }
9098     if (memAllocs[ALLOC_PARTITIONS] == YES)
9099         {
9100         for (i=0; i<numDefinedPartitions; i++)
9101             free (partitionNames[i]);
9102         free (partitionNames);
9103         partitionNames = NULL;
9104         for (i=0; i<numChar; i++)
9105             free (partitionId[i]);
9106         free (partitionId);
9107         numDefinedPartitions = 0;
9108         memAllocs[ALLOC_PARTITIONS] = NO;
9109         memoryLetFree = YES;
9110         }
9111     if (memAllocs[ALLOC_PARTITIONVARS] == YES)
9112         {
9113         free (numVars);
9114         numVars = NULL;
9115         free (tempNum);
9116         tempNum = NULL;
9117         free (activeParams[0]);
9118         activeParams[0] = NULL;
9119         free (linkTable[0]);
9120         linkTable[0] = NULL;
9121         tempLinkUnlinkVec = NULL;
9122         activeParts = NULL;
9123         tempLinkUnlinkVec = NULL;
9124         for (i=0; i<NUM_LINKED; i++)
9125             {
9126             linkTable[i] = NULL;
9127             activeParams[i] = NULL;
9128             }
9129         memAllocs[ALLOC_PARTITIONVARS] = NO;
9130         memoryLetFree = YES;
9131         }
9132
9133     ResetCharacterFlags();
9134
9135     if (memoryLetFree == YES)
9136         MrBayesPrint ("%s   Deleting previously defined characters\n", spacer);
9137
9138     return (NO_ERROR);
9139 }
9140
9141
9142 int FreeMatrix (void)
9143 {
9144     if (FreeCharacters() == ERROR)
9145         return ERROR;
9146
9147     return (FreeTaxa());
9148 }
9149
9150
9151 int FreeTaxa (void)
9152 {
9153     int i, memoryLetFree;
9154
9155     memoryLetFree = NO;
9156     if (memAllocs[ALLOC_TAXA] == YES)
9157         {
9158         if (taxaNames)
9159             {
9160             for (i=0; i<taxonCount; i++)
9161                 free (taxaNames[i]);
9162             }
9163         free (taxaNames);
9164         taxaNames = NULL;
9165         free (taxaInfo);
9166         taxaInfo = NULL;
9167         free (tipCalibration);
9168         tipCalibration = NULL;
9169         numTaxa = 0;
9170         memAllocs[ALLOC_TAXA] = NO;
9171         memoryLetFree = YES;
9172         }
9173     if (memAllocs[ALLOC_TMPSET] == YES)
9174         {
9175         free (tempSet);
9176         tempSet = NULL;
9177         free (tempSetNeg);
9178         tempSetNeg = NULL;
9179         memAllocs[ALLOC_TMPSET] = NO;
9180         memoryLetFree = YES;
9181         }
9182     if (memAllocs[ALLOC_TAXASETS] == YES)
9183         {
9184         for (i=0; i<numTaxaSets; i++)
9185             {
9186             free (taxaSetNames[i]);
9187             free (taxaSet[i]);
9188             }
9189         free (taxaSetNames);
9190         taxaSetNames = NULL;
9191         free (taxaSet);
9192         taxaSet = NULL;
9193         numTaxaSets = 0;
9194         memAllocs[ALLOC_TAXASETS] = NO;
9195         memoryLetFree = YES;
9196         }
9197     if (memAllocs[ALLOC_SPECIESPARTITIONS] == YES)
9198         {
9199         for (i=0; i<numDefinedSpeciespartitions; i++)
9200             free (speciespartitionNames[i]);
9201         free (speciespartitionNames);
9202         speciespartitionNames = NULL;
9203         for (i=0; i<numTaxa; i++)
9204             free (speciespartitionId[i]);
9205         free (speciespartitionId);
9206         speciespartitionId = NULL;
9207         numDefinedSpeciespartitions = 0;
9208         memAllocs[ALLOC_SPECIESPARTITIONS] = NO;
9209         memoryLetFree = YES;
9210         }
9211     if (memAllocs[ALLOC_CONSTRAINTS] == YES)
9212         {
9213         for (i=0; i<numDefinedConstraints; i++)
9214             {
9215             free(definedConstraint[i]);
9216             free(definedConstraintTwo[i]);
9217             free(definedConstraintPruned[i]);
9218             free(definedConstraintTwoPruned[i]);
9219             free (constraintNames[i]);
9220             }
9221         free (definedConstraint);
9222         definedConstraint = NULL;
9223         free (definedConstraintTwo);
9224         definedConstraintTwo = NULL;
9225         free (definedConstraintsType);
9226         definedConstraintsType = NULL;
9227         free (constraintNames);
9228         constraintNames = NULL;
9229         free (nodeCalibration);
9230         nodeCalibration = NULL;
9231         numDefinedConstraints = 0;
9232         free (tempActiveConstraints);
9233         tempActiveConstraints = NULL;
9234         memAllocs[ALLOC_CONSTRAINTS] = NO;
9235         memoryLetFree = YES;
9236         }
9237     if (numUserTrees > 0)
9238         {
9239         MrBayesPrint ("%s   Deleting user trees\n", spacer);
9240         for (i=0; i<numUserTrees; i++)
9241             {
9242             FreePolyTree(userTree[i]);
9243             userTree[i] = NULL;
9244             }
9245         numUserTrees = 0;
9246         }
9247
9248     FreeCharacters();
9249
9250     if (memoryLetFree == YES)
9251         MrBayesPrint ("%s   Deleting previously defined taxa\n", spacer);
9252
9253     /* reinitialize taxa variables */
9254     ResetTaxaFlags();
9255
9256     return NO_ERROR;
9257 }
9258
9259
9260 int GetNumPartDivisions (int n)
9261 {
9262     int         i, maxDiv, numDivs, *divFound;
9263     
9264     maxDiv = 0;
9265     for (i=0; i<numChar; i++)
9266         if (partitionId[i][n] > maxDiv)
9267             maxDiv = partitionId[i][n];
9268
9269     divFound = (int *) SafeCalloc (maxDiv, sizeof(int));
9270     
9271     for (i=0; i<maxDiv; i++)
9272         divFound[i] = NO;
9273     
9274     for (i=0; i<numChar; i++)
9275         divFound[partitionId[i][n]] = YES;
9276         
9277     numDivs = 0;
9278     for (i=0; i<maxDiv; i++)
9279         if (divFound[i] == YES)
9280             numDivs++;
9281     
9282     free (divFound);
9283
9284     return (numDivs + 1);
9285 }
9286
9287
9288 int GetToken (char *token, int *tokenType, char **sourceH)
9289 {
9290     int             allNumbers, foundExp, foundExpSign;
9291     register char   *temp;
9292     char            *tempMax;
9293     
9294     (*tokenType) = 0;
9295     temp = token;
9296     tempMax = temp + CMD_STRING_LENGTH - 10;
9297     
9298     while (IsWhite(**sourceH) == 1 || IsWhite(**sourceH) == 2)
9299         {
9300         if (IsWhite(**sourceH) == 2)
9301             {
9302             *tokenType = RETURNSYMBOL;
9303             /* foundNewLine = YES;  Why is this commented out?? */
9304             /* MrBayesPrint ("RETURN\n"); */
9305             }
9306         ++(*sourceH);
9307         }
9308     
9309     if (readWord == YES && **sourceH != '"')
9310         {
9311         if (**sourceH==';')
9312             {
9313             *temp++ = ';';
9314             *tokenType = SEMICOLON;
9315             }
9316         else
9317             {
9318             while (isgraph(**sourceH) && **sourceH!=';')
9319                 {
9320                 if (temp > tempMax)
9321                     {
9322                     *tokenType = NOTHING;
9323                     token[20]='\0';
9324                     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);
9325                     MrBayesPrint ("%s   Maximum allowed lenght of a token is %d\n", spacer,tempMax-token);
9326                     return (ERROR);
9327                     }
9328                 *temp++ = *(*sourceH)++;
9329                 }
9330             *tokenType = ALPHA;
9331             }
9332         *temp = '\0';
9333         readWord = NO;
9334         return (NO_ERROR);;
9335         }
9336
9337     *tokenType = UNKNOWN_TOKEN_TYPE;
9338     if (IsIn(**sourceH,"="))
9339         {
9340         *temp++ = *(*sourceH)++;
9341         *tokenType = EQUALSIGN;
9342         }
9343     else if (IsIn(**sourceH,";"))
9344         {
9345         *temp++ = *(*sourceH)++;
9346         *tokenType = SEMICOLON;
9347         }
9348     else if (IsIn(**sourceH,":"))
9349         {
9350         *temp++ = *(*sourceH)++;
9351         *tokenType = COLON;
9352         }
9353     else if (IsIn(**sourceH,","))
9354         {
9355         *temp++ = *(*sourceH)++;
9356         *tokenType = COMMA;
9357         }
9358     else if (IsIn(**sourceH,"#"))
9359         {
9360         *temp++ = *(*sourceH)++;
9361         *tokenType = POUNDSIGN;
9362         }
9363     else if (IsIn(**sourceH,"("))
9364         {
9365         *temp++ = *(*sourceH)++;
9366         *tokenType = LEFTPAR;
9367         }
9368     else if (IsIn(**sourceH,")"))
9369         {
9370         *temp++ = *(*sourceH)++;
9371         *tokenType = RIGHTPAR;
9372         }
9373     else if (IsIn(**sourceH,"{"))
9374         {
9375         *temp++ = *(*sourceH)++;
9376         *tokenType = LEFTCURL;
9377         }
9378     else if (IsIn(**sourceH,"}"))
9379         {
9380         *temp++ = *(*sourceH)++;
9381         *tokenType = RIGHTCURL;
9382         }
9383     else if (IsIn(**sourceH,"["))
9384         {
9385         *temp++ = *(*sourceH)++;
9386         *tokenType = LEFTCOMMENT;
9387         }
9388     else if (IsIn(**sourceH,"]"))
9389         {
9390         *temp++ = *(*sourceH)++;
9391         *tokenType = RIGHTCOMMENT;
9392         }
9393     else if (IsIn(**sourceH,"?"))
9394         {
9395         *temp++ = *(*sourceH)++;
9396         *tokenType = QUESTIONMARK;
9397         }
9398     else if (IsIn(**sourceH,"-"))
9399         {
9400         *temp++ = *(*sourceH)++;
9401         *tokenType = DASH;
9402         }
9403     else if (IsIn(**sourceH,"$"))
9404         {
9405         *temp++ = *(*sourceH)++;
9406         *tokenType = DOLLAR;
9407         }
9408     else if (IsIn(**sourceH,"\"") && readWord == YES)
9409         {
9410         (*sourceH)++;
9411         while (**sourceH != '"' && **sourceH != '\0')
9412             {
9413             if (temp > tempMax)
9414                 {
9415                 *tokenType = NOTHING;
9416                 token[20]='\0';
9417                 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);
9418                 MrBayesPrint ("%s   Maximum allowed lenght of a token is %d\n", spacer,tempMax-token);
9419                 return (ERROR);
9420                 }
9421             *temp++ = *((*sourceH)++);
9422             }
9423         *temp='\0';
9424         *tokenType = ALPHA;
9425         (*sourceH)++;
9426         readWord = NO;
9427         }
9428     else if (IsIn(**sourceH,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789."))
9429         {
9430         if (IsIn(**sourceH,"0123456789."))
9431             allNumbers = TRUE;
9432         else
9433             allNumbers = FALSE;
9434         foundExp = foundExpSign = FALSE;
9435         *temp++ = *(*sourceH)++;
9436         while (IsIn(**sourceH,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789.-+"))
9437             {
9438             if (temp > tempMax)
9439                 {
9440                 *tokenType = NOTHING;
9441                 token[20]='\0';
9442                 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);
9443                 MrBayesPrint ("%s   Maximum allowed lenght of a token is %d\n", spacer,tempMax-token);
9444                 return (ERROR);
9445                 }
9446             if (allNumbers == TRUE && !IsIn((*sourceH)[-1],"Ee") && **sourceH=='-')
9447                 break;
9448             else if (allNumbers == TRUE && IsIn(**sourceH,"Ee") && foundExp == NO)
9449                 foundExp = TRUE;
9450             else if (allNumbers == TRUE && IsIn(**sourceH,"+-") && IsIn((*sourceH)[-1],"Ee"))
9451                 foundExpSign = TRUE;
9452             else if (!IsIn(**sourceH,"0123456789."))
9453                 allNumbers = FALSE;
9454             *temp++ = *(*sourceH)++;
9455             }
9456         if (allNumbers == TRUE)
9457             *tokenType = NUMBER;
9458         else
9459             *tokenType = ALPHA;
9460         }
9461     else if (IsIn(**sourceH,"*"))
9462         {
9463         *temp++ = *(*sourceH)++;
9464         *tokenType = ASTERISK;
9465         }
9466     else if (IsIn(**sourceH,"/"))
9467         {
9468         *temp++ = *(*sourceH)++;
9469         *tokenType = FORWARDSLASH;
9470         }
9471     else if (IsIn(**sourceH,"'\\'"))
9472         {
9473         *temp++ = *(*sourceH)++;
9474         *tokenType = BACKSLASH;
9475         }
9476     else if (IsIn(**sourceH,"!"))
9477         {
9478         *temp++ = *(*sourceH)++;
9479         *tokenType = EXCLAMATIONMARK;
9480         }
9481     else if (IsIn(**sourceH,"%"))
9482         {
9483         *temp++ = *(*sourceH)++;
9484         *tokenType = PERCENT;
9485         }
9486     else if (IsIn(**sourceH,"\""))
9487         {
9488         *temp++ = *(*sourceH)++;
9489         *tokenType = QUOTATIONMARK;
9490         }
9491     else if (IsIn(**sourceH,"&"))
9492         {
9493         *temp++ = *(*sourceH)++;
9494         *tokenType = AMPERSAND;
9495         }
9496     else if (IsIn(**sourceH,"~+^@{}`><"))
9497         {
9498         *temp++ = *(*sourceH)++;
9499         *tokenType = WEIRD;
9500         }
9501     else if (IsIn(**sourceH,"|"))
9502         {
9503         *temp++ = *(*sourceH)++;
9504         *tokenType = VERTICALBAR;
9505         }
9506
9507     *temp = '\0';
9508     return (NO_ERROR);
9509 }
9510
9511
9512 int GetUserHelp (char *helpTkn)
9513 {
9514     int         i, j, k, tempInt;
9515     char        tempString[100];
9516     Model       *mp;
9517     
9518     if (!strcmp(helpTkn, "Begin"))
9519         {
9520         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9521         MrBayesPrint ("   Begin                                                                         \n");
9522         MrBayesPrint ("                                                                                 \n");
9523         MrBayesPrint ("   This command is used to format data or commands in the program. The correct   \n");
9524         MrBayesPrint ("   usage is                                                                      \n");
9525         MrBayesPrint ("                                                                                 \n");
9526         MrBayesPrint ("      begin <data or mrbayes>;                                                   \n");
9527         MrBayesPrint ("                                                                                 \n");
9528         MrBayesPrint ("   The two valid uses of the \"begin\" command, then, are                        \n");
9529         MrBayesPrint ("                                                                                 \n");
9530         MrBayesPrint ("      begin data;                                                                \n");
9531         MrBayesPrint ("      begin mrbayes;                                                             \n");
9532         MrBayesPrint ("                                                                                 \n");
9533         MrBayesPrint ("   The \"data\" specifier is used to specify the beginning of a data block; your \n");
9534         MrBayesPrint ("   character data should follow. For example, the following is an example of     \n");
9535         MrBayesPrint ("   a data block for four taxa and ten DNA sites:                                 \n");
9536         MrBayesPrint ("                                                                                 \n");
9537         MrBayesPrint ("      begin data;                                                                \n");
9538         MrBayesPrint ("         dimensions ntax=4 nchar=10;                                             \n");
9539         MrBayesPrint ("         format datatype=dna;                                                    \n");
9540         MrBayesPrint ("         matrix                                                                  \n");
9541         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9542         MrBayesPrint ("         taxon_2  AAGGATTCCA                                                     \n");
9543         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9544         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9545         MrBayesPrint ("         ;                                                                       \n");
9546         MrBayesPrint ("      end;                                                                       \n");
9547         MrBayesPrint ("                                                                                 \n");
9548         MrBayesPrint ("   The other commands -- dimensions, format, and matrix -- are discussed         \n");
9549         MrBayesPrint ("   in the appropriate help menu. The only thing to note here is that the         \n");
9550         MrBayesPrint ("   block begins with a \"begin data\" command. The \"mrbayes\" command is        \n");
9551         MrBayesPrint ("   used to enter commands specific to the MrBayes program into the file.         \n");
9552         MrBayesPrint ("   This allows you to automatically process commands on execution of the         \n");
9553         MrBayesPrint ("   program. The following is a simple mrbayes block:                             \n");
9554         MrBayesPrint ("                                                                                 \n");
9555         MrBayesPrint ("      begin mrbayes;                                                             \n");
9556         MrBayesPrint ("         charset first  = 1-10\\3;                                               \n");
9557         MrBayesPrint ("         charset second = 2-10\\3;                                               \n");
9558         MrBayesPrint ("         charset third  = 3-10\\3;                                               \n");
9559         MrBayesPrint ("      end;                                                                       \n");
9560         MrBayesPrint ("                                                                                 \n");
9561         MrBayesPrint ("   This mrbayes block sets off the three \"charset\" commands, used to           \n");
9562         MrBayesPrint ("   predefine some blocks of characters. The mrbayes block can be very useful.    \n");
9563         MrBayesPrint ("   For example, in this case, it would save you the time of typing the char-     \n");
9564         MrBayesPrint ("   acter sets each time you executed the file. Also, note that every             \n");
9565         MrBayesPrint ("   \"begin <data or mrbayes>\" command ends with an \"end\". Finally, you can    \n");
9566         MrBayesPrint ("   have so-called foreign blocks in the file. An example of a foreign block      \n");
9567         MrBayesPrint ("   would be \"begin paup\". The program will simply skip this block. This is     \n");
9568         MrBayesPrint ("   useful because it means that you can use the same file for MrBayes, PAUP*     \n");
9569         MrBayesPrint ("   or MacClade (although it isn't clear why you would want to use those other    \n");
9570         MrBayesPrint ("   programs).                                                                    \n");
9571         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9572         }
9573     else if (!strcmp(helpTkn, "End"))
9574         {
9575         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9576         MrBayesPrint ("   End                                                                           \n");
9577         MrBayesPrint ("                                                                                 \n");
9578         MrBayesPrint ("   This command is used to terminate a data or mrbayes block. The correct        \n");
9579         MrBayesPrint ("   usage is                                                                      \n");
9580         MrBayesPrint ("                                                                                 \n");
9581         MrBayesPrint ("      end;                                                                       \n");
9582         MrBayesPrint ("                                                                                 \n");
9583         MrBayesPrint ("   For more information on this, check the help for the \"begin\" command.       \n");
9584         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9585         }
9586     else if (!strcmp(helpTkn, "Endblock"))
9587         {
9588         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9589         MrBayesPrint ("   Endblock                                                                      \n");
9590         MrBayesPrint ("                                                                                 \n");
9591         MrBayesPrint ("   This is an older, deprecated version of \"End\", see that command.            \n");
9592         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9593         }
9594     else if (!strcmp(helpTkn, "Plot"))
9595         {
9596         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9597         MrBayesPrint ("   Plot                                                                          \n");
9598         MrBayesPrint ("                                                                                 \n");
9599         MrBayesPrint ("   This command plots specified parameters in the .p file or one of the .p files \n");
9600         MrBayesPrint ("   created during an MCMC analysis. An x-y graph of the parameter over the course\n");
9601         MrBayesPrint ("   of the chain is created. The command can be useful for visually diagnosing    \n");
9602         MrBayesPrint ("   convergence for many of the parameters of the phylogenetic model. The para-   \n");
9603         MrBayesPrint ("   meter to be plotted is specified by the \"parameter\" option. Several para-   \n");
9604         MrBayesPrint ("   meters can be plotted at once by using the \"match\" option, which has a      \n");
9605         MrBayesPrint ("   default value of \"perfect\". For example, if you were to set \"parameter = pi\"\n");
9606         MrBayesPrint ("   and \"match = consistentwith\", then all of the state frequency parameters    \n");
9607         MrBayesPrint ("   would be plotted. You can also set \"match=all\", in which case all of the    \n");
9608         MrBayesPrint ("   parameters are plotted.                                                       \n");
9609         MrBayesPrint ("                                                                                 \n");
9610         MrBayesPrint ("   Note that the \"Sump\" command provides a different set of convergence diag-  \n");
9611         MrBayesPrint ("   nostics tools that you may also want to explore. Unlike \"Plot\", \"Sump\" can\n");
9612         MrBayesPrint ("   compare two or more parameter samples and will calculate convergence diagnos- \n");
9613         MrBayesPrint ("   tics as wel as parameter summaries for the pooled sample.                     \n");
9614         MrBayesPrint ("                                                                                 \n");
9615         MrBayesPrint ("   Options:                                                                      \n");
9616         MrBayesPrint ("                                                                                 \n");
9617         MrBayesPrint ("   Relburnin     -- If this option is set to 'Yes', then a proportion of the     \n");
9618         MrBayesPrint ("                    samples will be discarded as burnin when creating the plot.  \n");
9619         MrBayesPrint ("                    The proportion to be discarded is set with Burninfrac (see   \n");
9620         MrBayesPrint ("                    Burninfrac below). When the Relburnin option is set to 'No', \n");
9621         MrBayesPrint ("                    then a specific number of samples is discarded instead. This \n");
9622         MrBayesPrint ("                    number is set by Burnin (see below). Note that the burnin    \n");
9623         MrBayesPrint ("                    setting is shared across the 'comparetree', 'sump' and 'sumt'\n");
9624         MrBayesPrint ("                    commands.                                                    \n");
9625         MrBayesPrint ("   Burnin        -- Determines the number of samples (not generations) that will \n");
9626         MrBayesPrint ("                    be discarded when summary statistics are calculated. The     \n");
9627         MrBayesPrint ("                    value of this option is only relevant when Relburnin is set  \n");
9628         MrBayesPrint ("                    to 'No'.                                                     \n");
9629         MrBayesPrint ("   Burninfrac    -- Determines the fraction of samples that will be discarded    \n");
9630         MrBayesPrint ("                    when creating a plot. The value of this parameter is only    \n");
9631         MrBayesPrint ("                    relevant when Relburnin is set to 'Yes'. Example: A value of \n");
9632         MrBayesPrint ("                    this option of 0.25 means that 25%% of the samples will be   \n");
9633         MrBayesPrint ("                    discarded.                                                   \n");
9634         MrBayesPrint ("   Filename      -- The name of the file to plot.                                \n");
9635         MrBayesPrint ("   Parameter     -- Specification of parameters to be plotted. See above for     \n");
9636         MrBayesPrint ("                    details.                                                     \n");
9637         MrBayesPrint ("   Match         -- Specifies how to match parameter names to the Parameter      \n");
9638         MrBayesPrint ("                    specification. See above for details.                        \n");
9639         MrBayesPrint ("                                                                                 \n");
9640         MrBayesPrint ("   Current settings:                                                             \n");
9641         MrBayesPrint ("                                                                                 \n");
9642         MrBayesPrint ("   Parameter       Options                      Current Setting                  \n");
9643         MrBayesPrint ("   ------------------------------------------------------------                  \n");
9644         MrBayesPrint ("   Relburnin       Yes/No                       %s                               \n", chainParams.relativeBurnin == YES ? "Yes" : "No");
9645         MrBayesPrint ("   Burnin          <number>                     %d                               \n", chainParams.chainBurnIn);
9646         MrBayesPrint ("   Burninfrac      <number>                     %1.2lf                           \n", chainParams.burninFraction);
9647         MrBayesPrint ("   Filename        <name>                       %s                               \n", plotParams.plotFileName);
9648         MrBayesPrint ("   Parameter       <name>                       %s                               \n", plotParams.parameter);
9649         MrBayesPrint ("   Match           Perfect/Consistentwith/All   %s                               \n", plotParams.match);
9650         MrBayesPrint ("                                                                                 \n");
9651         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9652         }
9653     else if (!strcmp(helpTkn, "Dimensions"))
9654         {
9655         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9656         MrBayesPrint ("   Dimensions                                                                    \n");
9657         MrBayesPrint ("                                                                                 \n");
9658         MrBayesPrint ("   This command is used in a data block to define the number of taxa and         \n");
9659         MrBayesPrint ("   characters. The correct usage is                                              \n");
9660         MrBayesPrint ("                                                                                 \n");
9661         MrBayesPrint ("      dimensions ntax=<number> nchar=<number>                                    \n");
9662         MrBayesPrint ("                                                                                 \n");
9663         MrBayesPrint ("   The dimensions must be the first command in a data block. The following       \n");
9664         MrBayesPrint ("   provides an example of the proper use of this command:                        \n");
9665         MrBayesPrint ("                                                                                 \n");
9666         MrBayesPrint ("      begin data;                                                                \n");
9667         MrBayesPrint ("         dimensions ntax=4 nchar=10;                                             \n");
9668         MrBayesPrint ("         format datatype=dna;                                                    \n");
9669         MrBayesPrint ("         matrix                                                                  \n");
9670         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9671         MrBayesPrint ("         taxon_2  AAGGATTCCA                                                     \n");
9672         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9673         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9674         MrBayesPrint ("         ;                                                                       \n");
9675         MrBayesPrint ("      end;                                                                       \n");
9676         MrBayesPrint ("                                                                                 \n");
9677         MrBayesPrint ("   Here, the dimensions command tells MrBayes to expect a matrix with four       \n");
9678         MrBayesPrint ("   taxa and 10 characters.                                                       \n");
9679         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9680         }
9681     else if (!strcmp(helpTkn, "Format"))
9682         {
9683         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9684         MrBayesPrint ("   Format                                                                        \n");
9685         MrBayesPrint ("                                                                                 \n");
9686         MrBayesPrint ("   This command is used in a data block to define the format of the char-        \n");
9687         MrBayesPrint ("   acter matrix. The correct usage is                                            \n");
9688         MrBayesPrint ("                                                                                 \n");
9689         MrBayesPrint ("      format datatype=<name> ... <parameter>=<option>                            \n");
9690         MrBayesPrint ("                                                                                 \n");
9691         MrBayesPrint ("   The format command must be the second command in a data block. The following  \n");
9692         MrBayesPrint ("   provides an example of the proper use of this command:                        \n");
9693         MrBayesPrint ("                                                                                 \n");
9694         MrBayesPrint ("      begin data;                                                                \n");
9695         MrBayesPrint ("         dimensions ntax=4 nchar=10;                                             \n");
9696         MrBayesPrint ("         format datatype=dna gap=-;                                              \n");
9697         MrBayesPrint ("         matrix                                                                  \n");
9698         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9699         MrBayesPrint ("         taxon_2  AAGGAT--CA                                                     \n");
9700         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9701         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9702         MrBayesPrint ("         ;                                                                       \n");
9703         MrBayesPrint ("      end;                                                                       \n");
9704         MrBayesPrint ("                                                                                 \n");
9705         MrBayesPrint ("   Here, the format command tells MrBayes to expect a matrix with DNA char-      \n");
9706         MrBayesPrint ("   acters and with gaps coded as \"-\".                                          \n");
9707         MrBayesPrint ("                                                                                 \n");
9708         MrBayesPrint ("   The following are valid options for format:                                   \n");
9709         MrBayesPrint ("                                                                                 \n");
9710         MrBayesPrint ("   Datatype   -- This parameter MUST BE INCLUDED in the format command. More-    \n");
9711         MrBayesPrint ("                 over, it must be the first parameter in the line. The           \n");
9712         MrBayesPrint ("                 datatype command specifies what type of characters are          \n");
9713         MrBayesPrint ("                 in the matrix. The following are valid options:                 \n");
9714         MrBayesPrint ("                    Datatype = Dna: DNA states (A,C,G,T,R,Y,M,K,S,W,H,B,         \n");
9715         MrBayesPrint ("                               V,D,N)                                            \n");
9716         MrBayesPrint ("                    Datatype = Rna: DNA states (A,C,G,U,R,Y,M,K,S,W,H,B,         \n");
9717         MrBayesPrint ("                               V,D,N)                                            \n");
9718         MrBayesPrint ("                    Datatype = Protein: Amino acid states (A,R,N,D,C,Q,E,        \n");
9719         MrBayesPrint ("                               G,H,I,L,K,M,F,P,S,T,W,Y,V)                        \n");
9720         MrBayesPrint ("                    Datatype = Restriction: Restriction site (0,1) states        \n");
9721         MrBayesPrint ("                    Datatype = Standard: Morphological (0,1) states              \n");
9722         MrBayesPrint ("                    Datatype = Continuous: Real number valued states             \n");
9723         MrBayesPrint ("                    Datatype = Mixed(<type>:<range>,...,<type>:<range>): A       \n");
9724         MrBayesPrint ("                               mixture of the above datatypes. For example,      \n");
9725         MrBayesPrint ("                               \"datatype=mixed(dna:1-100,protein:101-200)\"     \n");
9726         MrBayesPrint ("                               would specify a mixture of DNA and amino acid     \n");
9727         MrBayesPrint ("                               characters with the DNA characters occupying      \n");
9728         MrBayesPrint ("                               the first 100 sites and the amino acid char-      \n");
9729         MrBayesPrint ("                               acters occupying the last 100 sites.              \n");
9730         MrBayesPrint ("                                                                                 \n");
9731         MrBayesPrint ("   Interleave -- This parameter specifies whether the data matrix is in          \n");
9732         MrBayesPrint ("                 interleave format. The valid options are \"Yes\" or \"No\",     \n");
9733         MrBayesPrint ("                 with \"No\" as the default. An interleaved matrix looks like    \n");
9734         MrBayesPrint ("                                                                                 \n");
9735         MrBayesPrint ("                    format datatype=dna gap=- interleave=yes;                    \n");
9736         MrBayesPrint ("                    matrix                                                       \n");
9737         MrBayesPrint ("                    taxon_1  AACGATTCGT                                          \n");
9738         MrBayesPrint ("                    taxon_2  AAGGAT--CA                                          \n");
9739         MrBayesPrint ("                    taxon_3  AACGACTCCT                                          \n");
9740         MrBayesPrint ("                    taxon_4  AAGGATTCCT                                          \n");
9741         MrBayesPrint ("                                                                                 \n");
9742         MrBayesPrint ("                    taxon_1  CCTGGTAC                                            \n");
9743         MrBayesPrint ("                    taxon_2  CCTGGTAC                                            \n");
9744         MrBayesPrint ("                    taxon_3  ---GGTAG                                            \n");
9745         MrBayesPrint ("                    taxon_4  ---GGTAG                                            \n");
9746         MrBayesPrint ("                    ;                                                            \n");
9747         MrBayesPrint ("                                                                                 \n");
9748         MrBayesPrint ("   Gap        -- This parameter specifies the format for gaps. Note that         \n");
9749         MrBayesPrint ("                 gap character can only be a single character and that it        \n");
9750         MrBayesPrint ("                 cannot correspond to a standard state (e.g., A,C,G,T,R,Y,       \n");
9751         MrBayesPrint ("                 M,K,S,W,H,B,V,D,N for nucleotide data).                         \n");
9752         MrBayesPrint ("                                                                                 \n");
9753         MrBayesPrint ("   Missing    -- This parameter specifies the format for missing data. Note      \n");
9754         MrBayesPrint ("                 that the missing character can only be a single character and   \n");
9755         MrBayesPrint ("                 cannot correspond to a standard state (e.g., A,C,G,T,R,Y,       \n");
9756         MrBayesPrint ("                 M,K,S,W,H,B,V,D,N for nucleotide data). This is often an        \n");
9757         MrBayesPrint ("                 unnecessary parameter to set because many data types, such      \n");
9758         MrBayesPrint ("                 as nucleotide or amino acid, already have a missing char-       \n");
9759         MrBayesPrint ("                 acter specified. However, for morphological or restriction      \n");
9760         MrBayesPrint ("                 site data, \"missing=?\" is often used to specify ambiguity     \n");
9761         MrBayesPrint ("                 or unobserved data.                                             \n");
9762         MrBayesPrint ("                                                                                 \n");
9763         MrBayesPrint ("   Matchchar  -- This parameter specifies the matching character for the         \n");
9764         MrBayesPrint ("                 matrix. For example,                                            \n");
9765         MrBayesPrint ("                                                                                 \n");
9766         MrBayesPrint ("                    format datatype=dna gap=- matchchar=.;                       \n");
9767         MrBayesPrint ("                    matrix                                                       \n");
9768         MrBayesPrint ("                    taxon_1  AACGATTCGT                                          \n");
9769         MrBayesPrint ("                    taxon_2  ..G...--CA                                          \n");
9770         MrBayesPrint ("                    taxon_3  .....C..C.                                          \n");
9771         MrBayesPrint ("                    taxon_4  ..G.....C.                                          \n");
9772         MrBayesPrint ("                    ;                                                            \n");
9773         MrBayesPrint ("                                                                                 \n");
9774         MrBayesPrint ("                 is equivalent to                                                \n");
9775         MrBayesPrint ("                                                                                 \n");
9776         MrBayesPrint ("                    format datatype=dna gap=-;                                   \n");
9777         MrBayesPrint ("                    matrix                                                       \n");
9778         MrBayesPrint ("                    taxon_1  AACGATTCGT                                          \n");
9779         MrBayesPrint ("                    taxon_2  AAGGAT--CA                                          \n");
9780         MrBayesPrint ("                    taxon_3  AACGACTCCT                                          \n");
9781         MrBayesPrint ("                    taxon_4  AAGGATTCCT                                          \n");
9782         MrBayesPrint ("                    ;                                                            \n");
9783         MrBayesPrint ("                                                                                 \n");
9784         MrBayesPrint ("   The only non-standard NEXUS format option is the use of the \"mixed\",        \n");
9785         MrBayesPrint ("   \"restriction\", \"standard\" and \"continuous\" datatypes. Hence, if         \n");
9786         MrBayesPrint ("   you use any of these datatype specifiers, a program like PAUP* or             \n");
9787         MrBayesPrint ("   MacClade will report an error (as they should because MrBayes is not          \n");
9788         MrBayesPrint ("   strictly NEXUS compliant).                                                    \n");
9789         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9790         }
9791     else if (!strcmp(helpTkn, "Matrix"))
9792         {
9793         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9794         MrBayesPrint ("   Matrix                                                                        \n");
9795         MrBayesPrint ("                                                                                 \n");
9796         MrBayesPrint ("   This command specifies the actual data for the phylogenetic analysis.         \n");
9797         MrBayesPrint ("   The character matrix should follow the dimensions and format commands         \n");
9798         MrBayesPrint ("   in a data block. The matrix can have all of the characters for a taxon        \n");
9799         MrBayesPrint ("   on a single line:                                                             \n");
9800         MrBayesPrint ("                                                                                 \n");
9801         MrBayesPrint ("      begin data;                                                                \n");
9802         MrBayesPrint ("         dimensions ntax=4 nchar=10;                                             \n");
9803         MrBayesPrint ("         format datatype=dna gap=-;                                              \n");
9804         MrBayesPrint ("         matrix                                                                  \n");
9805         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9806         MrBayesPrint ("         taxon_2  AAGGAT--CA                                                     \n");
9807         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9808         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9809         MrBayesPrint ("         ;                                                                       \n");
9810         MrBayesPrint ("      end;                                                                       \n");
9811         MrBayesPrint ("                                                                                 \n");
9812         MrBayesPrint ("   or be in \"interleaved\" format:                                              \n");
9813         MrBayesPrint ("                                                                                 \n");
9814         MrBayesPrint ("      begin data;                                                                \n");
9815         MrBayesPrint ("         dimensions ntax=4 nchar=20;                                             \n");
9816         MrBayesPrint ("         format datatype=dna gap=- interleave=yes;                               \n");
9817         MrBayesPrint ("         matrix                                                                  \n");
9818         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9819         MrBayesPrint ("         taxon_2  AAGGAT--CA                                                     \n");
9820         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9821         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9822         MrBayesPrint ("                                                                                 \n");
9823         MrBayesPrint ("         taxon_1  TTTTCGAAGC                                                     \n");
9824         MrBayesPrint ("         taxon_2  TTTTCGGAGC                                                     \n");
9825         MrBayesPrint ("         taxon_3  TTTTTGATGC                                                     \n");
9826         MrBayesPrint ("         taxon_4  TTTTCGGAGC                                                     \n");
9827         MrBayesPrint ("         ;                                                                       \n");
9828         MrBayesPrint ("      end;                                                                       \n");
9829         MrBayesPrint ("                                                                                 \n");
9830         MrBayesPrint ("   Note that the taxon names must not have spaces. If you really want to         \n");
9831         MrBayesPrint ("   indicate a space in a taxon name (perhaps between a genus and species         \n");
9832         MrBayesPrint ("   name), then you might use an underline (\"_\"). There should be at            \n");
9833         MrBayesPrint ("   least a single space after the taxon name, separating the name from           \n");
9834         MrBayesPrint ("   the actual data on that line. There can be spaces between the char-           \n");
9835         MrBayesPrint ("   acters.                                                                       \n");
9836         MrBayesPrint ("                                                                                 \n");
9837         MrBayesPrint ("   If you have mixed data, then you specify all of the data in the same          \n");
9838         MrBayesPrint ("   matrix. Here is an example that includes two different data types:            \n");
9839         MrBayesPrint ("                                                                                 \n");
9840         MrBayesPrint ("      begin data;                                                                \n");
9841         MrBayesPrint ("         dimensions ntax=4 nchar=20;                                             \n");
9842         MrBayesPrint ("         format datatype=mixed(dna:1-10,standard:21-30) interleave=yes;          \n");
9843         MrBayesPrint ("         matrix                                                                  \n");
9844         MrBayesPrint ("         taxon_1  AACGATTCGT                                                     \n");
9845         MrBayesPrint ("         taxon_2  AAGGAT--CA                                                     \n");
9846         MrBayesPrint ("         taxon_3  AACGACTCCT                                                     \n");
9847         MrBayesPrint ("         taxon_4  AAGGATTCCT                                                     \n");
9848         MrBayesPrint ("                                                                                 \n");
9849         MrBayesPrint ("         taxon_1  0001111111                                                     \n");
9850         MrBayesPrint ("         taxon_2  0111110000                                                     \n");
9851         MrBayesPrint ("         taxon_3  1110000000                                                     \n");
9852         MrBayesPrint ("         taxon_4  1000001111                                                     \n");
9853         MrBayesPrint ("         ;                                                                       \n");
9854         MrBayesPrint ("      end;                                                                       \n");
9855         MrBayesPrint ("                                                                                 \n");
9856         MrBayesPrint ("   The matrix command is terminated by a semicolon.                              \n");
9857         MrBayesPrint ("                                                                                 \n");
9858         MrBayesPrint ("   Finally, just a note on data presentation. It is much easier for others       \n");
9859         MrBayesPrint ("   to (1) understand your data and (2) repeat your analyses if you make          \n");
9860         MrBayesPrint ("   your data clean, comment it liberally (using the square brackets), and        \n");
9861         MrBayesPrint ("   embed the commands you used in a publication in the mrbayes block.            \n");
9862         MrBayesPrint ("   Remember that the data took a long time for you to collect. You might         \n");
9863         MrBayesPrint ("   as well spend a little time making the data file look nice and clear to       \n");
9864         MrBayesPrint ("   any that may later request the data for further analysis.                     \n");
9865         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9866         }
9867     else if (!strcmp(helpTkn, "Pairs"))
9868         {
9869         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9870         MrBayesPrint ("   Pairs                                                                         \n");
9871         MrBayesPrint ("                                                                                 \n");
9872         MrBayesPrint ("   This command is used to specify pairs of nucleotides. For example, your       \n");
9873         MrBayesPrint ("   data may be RNA sequences with a known secondary structure of stems and       \n");
9874         MrBayesPrint ("   loops. Substitutions in nucleotides involved in a Watson-Crick pairing        \n");
9875         MrBayesPrint ("   in stems are not strictly independent; a change in one changes the prob-      \n");
9876         MrBayesPrint ("   ability of a change in the partner. A solution to this problem is to          \n");
9877         MrBayesPrint ("   expand the model around the pair of nucleotides in the stem. This             \n");
9878         MrBayesPrint ("   command allows you to do this. The correct usage is:                          \n");
9879         MrBayesPrint ("                                                                                 \n");
9880         MrBayesPrint ("      pairs <NUC1>:<NUC2>, <NUC1>:<NUC2>,..., <NUC1>:<NUC2>;                     \n");
9881         MrBayesPrint ("                                                                                 \n");
9882         MrBayesPrint ("   For example,                                                                  \n");
9883         MrBayesPrint ("                                                                                 \n");
9884         MrBayesPrint ("      pairs 30:56, 31:55, 32:54, 33:53, 34:52, 35:51, 36:50;                     \n");
9885         MrBayesPrint ("                                                                                 \n");
9886         MrBayesPrint ("   specifies pairings between nucleotides 30 and 56, 31 and 55, etc. Only        \n");
9887         MrBayesPrint ("   nucleotide data (DNA or RNA) may be paired using this command. Note that      \n");
9888         MrBayesPrint ("   in order for the program to actually implement a \"doublet\" model            \n");
9889         MrBayesPrint ("   involving a 16 X 16 rate matrix, you must specify that the structure of       \n");
9890         MrBayesPrint ("   the model is 16 X 16 using \"lset nucmodel=doublet\".                         \n");
9891         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9892         }
9893     else if (!strcmp(helpTkn, "Databreaks"))
9894         {
9895         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9896         MrBayesPrint ("   Databreaks                                                                    \n");
9897         MrBayesPrint ("                                                                                 \n");
9898         MrBayesPrint ("   This command is used to specify breaks in your input data matrix. Your        \n");
9899         MrBayesPrint ("   data may be a mixture of genes or a mixture of different types of data.       \n");
9900         MrBayesPrint ("   Some of the models implemented by MrBayes account for nonindependence at      \n");
9901         MrBayesPrint ("   adjacent characters. The autocorrelated gamma model, for example, allows      \n");
9902         MrBayesPrint ("   rates at adjacent sites to be correlated. However, there is no way for        \n");
9903         MrBayesPrint ("   such a model to tell whether two sites, adjacent in the matrix, are           \n");
9904         MrBayesPrint ("   actually separated by many kilobases or megabases in the genome. The          \n");
9905         MrBayesPrint ("   databreaks command allows you to specify such breaks. The correct             \n");
9906         MrBayesPrint ("   usage is:                                                                     \n");
9907         MrBayesPrint ("                                                                                 \n");
9908         MrBayesPrint ("      databreaks <break 1> <break 2> <break 3> ...                               \n");
9909         MrBayesPrint ("                                                                                 \n");
9910         MrBayesPrint ("   For example, say you have a data matrix of 3204 characters that include       \n");
9911         MrBayesPrint ("   nucleotide data from three genes. The first gene covers characters 1 to       \n");
9912         MrBayesPrint ("   970, the second gene covers characters 971 to 2567, and the third gene        \n");
9913         MrBayesPrint ("   covers characters 2568 to 3204. Also, let's assume that the genes are         \n");
9914         MrBayesPrint ("   not directly adjacent to one another in the genome, as might be likely        \n");
9915         MrBayesPrint ("   if you have mitochondrial sequences. In this case, you can specify            \n");
9916         MrBayesPrint ("   breaks between the genes using:                                               \n");
9917         MrBayesPrint ("                                                                                 \n");
9918         MrBayesPrint ("      databreaks 970 2567;                                                       \n");
9919         MrBayesPrint ("                                                                                 \n");
9920         MrBayesPrint ("   The first break, between genes one and two, is after character 970 and        \n");
9921         MrBayesPrint ("   the second break, between genes two and three, is after character 2567.       \n");
9922         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9923         }
9924     else if (!strcmp(helpTkn, "Acknowledgments"))
9925         {
9926         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9927         MrBayesPrint ("   Acknowledgments                                                               \n");
9928         MrBayesPrint ("                                                                                 \n");
9929         MrBayesPrint ("   This command shows the authors' acknowledgments.                              \n");
9930         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9931         }
9932     else if (!strcmp(helpTkn, "About"))
9933         {
9934         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9935         MrBayesPrint ("   About                                                                         \n");
9936         MrBayesPrint ("                                                                                 \n");
9937         MrBayesPrint ("   This command provides some general information about the program.             \n");
9938         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9939         }
9940     else if (!strcmp(helpTkn, "Version"))
9941         {
9942         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9943         MrBayesPrint ("   Version                                                                       \n");
9944         MrBayesPrint ("                                                                                 \n");
9945         MrBayesPrint ("   This command shows the release version of the program.                        \n");
9946         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9947         }
9948     else if (!strcmp(helpTkn, "Citations"))
9949         {
9950         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9951         MrBayesPrint ("   Citations                                                                     \n");
9952         MrBayesPrint ("                                                                                 \n");
9953         MrBayesPrint ("   This command shows a thorough list of citations you may consider using        \n");
9954         MrBayesPrint ("   when publishing the results of a MrBayes analysis.                            \n");
9955         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9956         }
9957     else if (!strcmp(helpTkn, "Showmatrix"))
9958         {
9959         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9960         MrBayesPrint ("   Showmatrix                                                                    \n");
9961         MrBayesPrint ("                                                                                 \n");
9962         MrBayesPrint ("   This command shows the character matrix currently in memory.                  \n");
9963         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9964         }
9965     else if (!strcmp(helpTkn, "Showbeagle"))
9966         {
9967         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9968         MrBayesPrint ("   Showbeagle                                                                    \n");
9969         MrBayesPrint ("                                                                                 \n");
9970         MrBayesPrint ("   This command shows available BEAGLE resources.                                \n");
9971         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9972         }
9973     else if (!strcmp(helpTkn, "Speciespartition"))
9974         {
9975         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
9976         MrBayesPrint ("   Speciespartition                                                              \n");
9977         MrBayesPrint ("                                                                                 \n");
9978         MrBayesPrint ("   Defines a partition of tips into species. The format for the speciespartition \n");
9979         MrBayesPrint ("   command is                                                                    \n");
9980         MrBayesPrint ("                                                                                 \n");
9981         MrBayesPrint ("      Speciespartition <name> = <species name>:<taxon list> ,...,<sp nm>:<tx lst>\n");
9982         MrBayesPrint ("                                                                                 \n");
9983         MrBayesPrint ("   The command enumerates comma separated list of pairs consisting of 'species   \n");
9984         MrBayesPrint ("   name' and 'taxon list'. The 'taxon list' is a standard taxon list, as used by \n");
9985         MrBayesPrint ("   the 'Taxset' command. This means that you can use either the index or the name\n");
9986         MrBayesPrint ("   of a sequence ('taxon'). Ranges are specified using a dash, and a period can  \n");
9987         MrBayesPrint ("   be used as a synonym of the last sequence in the matrix.                      \n");
9988         MrBayesPrint ("                                                                                 \n");
9989         MrBayesPrint ("   For exammple: speciespartition species = SpeciesA: 1, SpeciesB: 2-.           \n");
9990         MrBayesPrint ("   Here, we name two species. SpeciesA is represented by a single sequence while \n");
9991         MrBayesPrint ("   SpeciesB is represented by all remaining sequences in the matrix.             \n");
9992         MrBayesPrint ("   Each sequence is specified by its row index in the data matrix.               \n");
9993         MrBayesPrint ("                                                                                 \n");
9994         MrBayesPrint ("   As with ordinary partitioning you may define multiple species partitioning    \n");
9995         MrBayesPrint ("   scheme. You have to use command 'set speciespartition' to enable use of one of\n");
9996         MrBayesPrint ("   them.                                                                         \n"); 
9997         MrBayesPrint ("                                                                                 \n");
9998         MrBayesPrint ("   Currently defined Speciespartitions:                                          \n");
9999         MrBayesPrint ("                                                                                 \n");
10000         MrBayesPrint ("   Number  Speciespartition name        Number of species                        \n");
10001         MrBayesPrint ("   --------------------------------------------------------------------------    \n");
10002         for (i=0; i<numDefinedSpeciespartitions; i++)
10003             {
10004             tempInt=0;
10005             for (j=0; j<numTaxa; j++)
10006                 {
10007                 if (tempInt < speciespartitionId[j][i])
10008                     tempInt = speciespartitionId[j][i];
10009                 }
10010             MrBayesPrint ("   %4d    %-24.24s   %4d",i+1, speciespartitionNames[i], tempInt);
10011             MrBayesPrint ("\n");
10012             }
10013         MrBayesPrint ("                                                                                \n");
10014         MrBayesPrint ("   --------------------------------------------------------------------------   \n");
10015         }
10016     else if (!strcmp(helpTkn, "Constraint"))
10017         {
10018         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10019         MrBayesPrint ("   Constraint                                                                    \n");
10020         MrBayesPrint ("                                                                                 \n");
10021         MrBayesPrint ("   This command defines a tree constraint. The format for the constraint         \n");
10022         MrBayesPrint ("   command is                                                                    \n");
10023         MrBayesPrint ("                                                                                 \n");
10024         MrBayesPrint ("      constraint <name> [hard|negative|partial] = <taxon list> [:<taxon list>]   \n");
10025         MrBayesPrint ("                                                                                 \n");
10026         MrBayesPrint ("   There are three types of constraint implemented in MrBayes. The type of the   \n");
10027         MrBayesPrint ("   constraint is specified by using one of the three keywords 'hard', 'negative',\n");
10028         MrBayesPrint ("   or 'partial' right after the name of the constraint. If no type is specified, \n");
10029         MrBayesPrint ("   then the constraint is assumed to be 'hard'.                                  \n");
10030         MrBayesPrint ("                                                                                 \n");
10031         MrBayesPrint ("   In a rooted tree, a 'hard' constraint forces the taxa in the list to form a   \n");
10032         MrBayesPrint ("   monophyletic group. In an unrooted tree, the taxon split that separates the   \n");
10033         MrBayesPrint ("   taxa in the list from other taxa is forced to be present. The interpretation  \n");
10034         MrBayesPrint ("   of this depends on whether the tree is rooted on a taxon outside the list or  \n");
10035         MrBayesPrint ("   a taxon in the list. If the outgroup is excluded , the taxa in the list are   \n");
10036         MrBayesPrint ("   assumed to form a monophyletic group, but if the outgroup is included, the    \n");
10037         MrBayesPrint ("   taxa that are not in the list are forced together.                            \n");
10038         MrBayesPrint ("                                                                                 \n");
10039         MrBayesPrint ("   A 'negative' constraint bans all the trees that have the listed taxa in the   \n");
10040         MrBayesPrint ("   same subtree. In other words, it is the opposite of a hard constraint.        \n");
10041         MrBayesPrint ("                                                                                 \n");
10042         MrBayesPrint ("   A 'partial' or backbone constraint is defined in terms of two sets of taxa    \n");
10043         MrBayesPrint ("   separated by a colon character. The constraint forces all taxa in the first   \n");
10044         MrBayesPrint ("   list to form a monophyletic group that does not include any taxon in the      \n");
10045         MrBayesPrint ("   second list. Taxa that are not included in either list can be placed in any   \n");
10046         MrBayesPrint ("   position on the tree, either inside or outside the constrained group. In an   \n");
10047         MrBayesPrint ("   unrooted tree, the two taxon lists can be switched with each other with no    \n");
10048         MrBayesPrint ("   effect. For a rooted tree, it is the taxa in the first list that have to be   \n");
10049         MrBayesPrint ("   monophyletic, that is, these taxa must share a common ancestor not shared with\n");
10050         MrBayesPrint ("   any taxon in the second list. The taxa in the second list may or may not fall \n");
10051         MrBayesPrint ("   in a monophyletic group depending on the rooting of the tree.                 \n");
10052         MrBayesPrint ("                                                                                 \n");
10053         MrBayesPrint ("   A list of taxa can be specified using a taxset, taxon names, taxon numbers, or\n");
10054         MrBayesPrint ("   any combination of the above, sepatated by spaces. The constraint is treated  \n");
10055         MrBayesPrint ("   as an absolute requirement of trees, that is, trees that are not compatible   \n");
10056         MrBayesPrint ("   with the constraint have zero prior (and hence zero posterior) probabilty.    \n");
10057         MrBayesPrint ("                                                                                 \n");
10058         MrBayesPrint ("   If you are interested in inferring ancestral states for a particular node,    \n");
10059         MrBayesPrint ("   you need to 'hard' constrain that node first using the 'constraint' command.  \n");
10060         MrBayesPrint ("   The same applies if you wish to calibrate an interior node in a dated         \n");
10061         MrBayesPrint ("   analysis. For more information on how to infer ancestral states, see the help \n");
10062         MrBayesPrint ("   for the 'report' command. For more on dating, see the 'calibrate' command.    \n");
10063         MrBayesPrint ("                                                                                 \n");
10064         MrBayesPrint ("   It is important to note that simply defining a constraint using this          \n");
10065         MrBayesPrint ("   command is not sufficient for the program to actually implement the           \n");
10066         MrBayesPrint ("   constraint in an analysis. You must also enforce the constraints using        \n");
10067         MrBayesPrint ("   'prset topologypr = constraints (<list of constraints>)'. For more infor-     \n");
10068         MrBayesPrint ("   mation on this, see the help on the 'prset' command.                          \n");
10069         MrBayesPrint ("                                                                                 \n");
10070         MrBayesPrint ("   Examples:                                                                     \n");
10071         MrBayesPrint ("                                                                                 \n");
10072         MrBayesPrint ("      constraint myclade = Homo Pan Gorilla                                      \n");
10073         MrBayesPrint ("                                                                                 \n");
10074         MrBayesPrint ("   Defines a hard constraint forcing Homo, Pan, and Gorilla to form a mono-      \n");
10075         MrBayesPrint ("   phyletic group or a split that does not include any other taxa.               \n");
10076         MrBayesPrint ("                                                                                 \n");
10077         MrBayesPrint ("      constraint forbiddenclade negative = Homo Pan Gorilla                      \n");
10078         MrBayesPrint ("                                                                                 \n");
10079         MrBayesPrint ("   Defines a negative constraint that associates all trees where Homon, Pan, and \n");
10080         MrBayesPrint ("   Gorilla form a monophyletic group with zero posterior probability. In other   \n");
10081         MrBayesPrint ("   words, such trees will not be sampled during MCMC.                            \n");
10082         MrBayesPrint ("                                                                                 \n");
10083         MrBayesPrint ("      constraint backbone partial = Homo Gorilla : Mus                           \n");
10084         MrBayesPrint ("                                                                                 \n");
10085         MrBayesPrint ("   Defines a partial constraint that keeps Mus outside of the clade defined by   \n");
10086         MrBayesPrint ("   the most recent common ancestor of Homo and Gorilla. Other taxa are allowed to\n");
10087         MrBayesPrint ("   sit anywhere in the tree. Note that this particular constraint is meaningless \n");
10088         MrBayesPrint ("   in unrooted trees. MrBayes does not assume anything about the position of the \n");
10089         MrBayesPrint ("   outgroup unless it is explicitly included in the partial constraint. Therefore\n");
10090         MrBayesPrint ("   a partial constraint must have at least two taxa on each side of the ':' to be\n");
10091         MrBayesPrint ("   useful in analyses of unrooted trees. The case is different for rooted trees, \n");
10092         MrBayesPrint ("   where it is sufficient for a partial constraint to have more than one taxon   \n");
10093         MrBayesPrint ("   before the ':', as in the example given above, to constrain tree space.       \n");
10094         MrBayesPrint ("                                                                                 \n");
10095         MrBayesPrint ("   To define a more complex constraint tree, simply combine constraints into a   \n");
10096         MrBayesPrint ("   list when issuing the 'prset topologypr' command.                             \n");
10097         MrBayesPrint ("                                                                                 \n");
10098         if (numDefinedConstraints > 0)
10099             {
10100             MrBayesPrint ("   Currently defined constraints:                                                \n");
10101             MrBayesPrint ("                                                                                 \n");
10102             MrBayesPrint ("   Number  Constraint name          type      Number of taxa in[:out]            \n");
10103             MrBayesPrint ("   --------------------------------------------------------------------------    \n");       
10104             }
10105         for (i=0; i<numDefinedConstraints; i++)
10106             {
10107             strncpy (tempString, constraintNames[i], 22);
10108             MrBayesPrint ("   %4d    %-22.22s   ",i+1, tempString);
10109             if (definedConstraintsType[i] == HARD)
10110                 MrBayesPrint ("hard      ");
10111             else if (definedConstraintsType[i] == PARTIAL)
10112                 MrBayesPrint ("partial   ");
10113             else
10114                 {
10115                 assert (definedConstraintsType[i] == NEGATIVE);
10116                 MrBayesPrint ("negative  ");
10117                 }
10118             k = NumBits (definedConstraint[i], numTaxa/nBitsInALong + 1);
10119             MrBayesPrint ("%d", k);
10120             if (definedConstraintsType[i] == PARTIAL)
10121                 {
10122                 k = NumBits (definedConstraintTwo[i], numTaxa/nBitsInALong + 1);
10123                 MrBayesPrint (":%d", k);
10124                 }
10125         MrBayesPrint ("\n");
10126             }
10127         MrBayesPrint ("                                                                                \n");
10128         MrBayesPrint ("   --------------------------------------------------------------------------   \n");
10129         }
10130     else if (!strcmp(helpTkn, "Calibrate"))
10131         {
10132         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10133         MrBayesPrint ("   Calibrate                                                                     \n");
10134         MrBayesPrint ("                                                                                 \n");
10135         MrBayesPrint ("   This command dates a terminal or interior node in the tree. The format is     \n");
10136         MrBayesPrint ("                                                                                 \n");
10137         MrBayesPrint ("      calibrate <node_name> = <age_prior>                                        \n");
10138         MrBayesPrint ("                                                                                 \n");
10139         MrBayesPrint ("   where <node_name> is the name of a defined interior constraint node or the    \n");
10140         MrBayesPrint ("   name of a terminal node (tip) and <age_prior> is a prior probability distribu-\n");
10141         MrBayesPrint ("   tion on the age of the node. The latter can either be a fixed date or a date  \n");
10142         MrBayesPrint ("   drawn from one of the available prior probability distributions. In general,  \n");
10143         MrBayesPrint ("   the available prior probability distributions are parameterized in terms of   \n");
10144         MrBayesPrint ("   the expected mean age of the distribution to facilitate for users. Some dis-  \n");
10145         MrBayesPrint ("   tributions put a positive probability on all ages above 0.0, while others in- \n");
10146         MrBayesPrint ("   clude a minimum-age constraint and sometimes a maximum-age constraint. The    \n");
10147         MrBayesPrint ("   available distributions and their parameters are:                             \n");
10148         MrBayesPrint ("                                                                                 \n");
10149         MrBayesPrint ("      calibrate <node_name> = fixed(<age>)                                       \n");
10150         MrBayesPrint ("      calibrate <node_name> = uniform(<min_age>,<max_age>)                       \n");
10151         MrBayesPrint ("      calibrate <node_name> = offsetexponential(<min_age>,<mean_age>)            \n");
10152         MrBayesPrint ("      calibrate <node_name> = truncatednormal(<min_age>,<mean_age>,<stdev>)      \n");
10153         MrBayesPrint ("      calibrate <node_name> = lognormal(<mean_age>,<stdev>)                      \n");
10154         MrBayesPrint ("      calibrate <node_name> = offsetlognormal(<min_age>,<mean_age>,<stdev>)      \n");
10155         MrBayesPrint ("      calibrate <node_name> = gamma(<mean_age>,<stdev>)                          \n");
10156         MrBayesPrint ("      calibrate <node_name> = offsetgamma(<min_age>,<mean_age>,<stdev>)          \n");
10157         MrBayesPrint ("                                                                                 \n");
10158         MrBayesPrint ("   Note that mean_age is always the mean age and stdev the standard deviation of \n");
10159         MrBayesPrint ("   the distribution measured in user-defined time units. This way of specifying  \n");
10160         MrBayesPrint ("   the distribution parameters is often different from the parameterization used \n");
10161         MrBayesPrint ("   elsewhere in the program. For instance, the standard parameters of the gamma  \n");
10162         MrBayesPrint ("   distribution used by MrBayes are shape (alpha) and rate (beta). If you want   \n");
10163         MrBayesPrint ("   to use the standard parameterization, the conversions are as follows:         \n");
10164         MrBayesPrint ("                                                                                 \n");
10165         MrBayesPrint ("      exponential distributon: mean    = 1 / rate                                \n");
10166         MrBayesPrint ("      gamma distributon:       mean    = alpha / beta                            \n");
10167         MrBayesPrint ("                               st.dev. = square_root (alpha / beta^2)            \n");
10168         MrBayesPrint ("      lognormal distributon:   mean    = exp (mean_log + st.dev._log^2/2)        \n");
10169         MrBayesPrint ("                               st.dev. = square_root ((exp (st.dev._log^2) - 1)  \n");
10170         MrBayesPrint ("                                         * (exp (2*mean_log + st.dev._log^2))    \n");
10171         MrBayesPrint ("                                                                                 \n");
10172         MrBayesPrint ("   The truncated normal distribution is an exception in that the mean_age and    \n");
10173         MrBayesPrint ("   stdev parameters are the mean and standard deviation of the underlying non-   \n");
10174         MrBayesPrint ("   truncated normal distribution. The truncation will cause the modified distri- \n");
10175         MrBayesPrint ("   bution to have a higher mean and lower standard deviation. The magnitude of   \n");
10176         MrBayesPrint ("   that effect depends on how much of the tail of the distribution is removed.   \n");
10177         MrBayesPrint ("                                                                                 \n");
10178         MrBayesPrint ("   Note that previous to version 3.2.2, MrBayes used the standard rate parameter-\n");
10179         MrBayesPrint ("   ization of the offset exponential. This should not cause a problem in most    \n");
10180         MrBayesPrint ("   cases because the old parameterization will result in an error in more recent \n");
10181         MrBayesPrint ("   versions of MrBayes, and the likely source of the error is given in the error \n");
10182         MrBayesPrint ("   message.                                                                      \n");
10183         MrBayesPrint ("                                                                                 \n");
10184         MrBayesPrint ("   For a practical example, assume that we had three fossil terminals named      \n");
10185         MrBayesPrint ("   'FossilA', 'FossilB', and 'FossilC'. Assume further that we want to fix the   \n");
10186         MrBayesPrint ("   age of FossilA to 100.0 million years, we think that FossilB is somewhere     \n");
10187         MrBayesPrint ("   between 100.0 and 200.0 million years old, and that FossilC is at least 300.0 \n");
10188         MrBayesPrint ("   million years old, possibly older but relatively unlikely to be more than     \n");
10189         MrBayesPrint ("   400.0 million years old. Then we might use the commands:                      \n");
10190         MrBayesPrint ("                                                                                 \n");
10191         MrBayesPrint ("      calibrate FossilA = fixed(100) FossilB = uniform(100,200)                  \n");
10192         MrBayesPrint ("      calibrate FossilC = offsetexponential(300,400)                             \n");
10193         MrBayesPrint ("                                                                                 \n");
10194         MrBayesPrint ("   Note that it is possible to give more than one calibration for each           \n");
10195         MrBayesPrint ("   'calibrate' statement. Thus, 'calibrate FossilA=<setting> FossilB=<setting>'  \n");
10196         MrBayesPrint ("   would be a valid statement.                                                   \n");
10197         MrBayesPrint ("                                                                                 \n");
10198         MrBayesPrint ("   To actually use the calibrations to obtain dated trees, you also need to set  \n");
10199         MrBayesPrint ("   a clock model using relevant 'brlenspr' and 'nodeagepr' options of the 'prset'\n");
10200         MrBayesPrint ("   command. You may also want to examine the 'clockvarpr' and 'clockratepr' op-  \n");
10201         MrBayesPrint ("   tions. Furthermore, you need to activate the relevant constraint(s) using     \n");
10202         MrBayesPrint ("   'topologypr', if you use any dated interior nodes in the tree.                \n");
10203         MrBayesPrint ("                                                                                 \n");
10204         MrBayesPrint ("   You may wish to remove a calibration from an interior or terminal node, which \n");
10205         MrBayesPrint ("   has previously been calibrated. You can do that using                         \n");
10206         MrBayesPrint ("                                                                                 \n");
10207         MrBayesPrint ("      calibrate <node_name> = unconstrained                                      \n");
10208         MrBayesPrint ("                                                                                 \n");
10209         j = 0;
10210         for (i=0; i<numTaxa; i++)
10211             if (tipCalibration[i].prior != unconstrained)
10212                 j++;
10213         for (i=0; i<numDefinedConstraints; i++)
10214             if (nodeCalibration[i].prior != unconstrained)
10215                 j++;
10216         if (j > 0)
10217             {
10218             MrBayesPrint ("                                                                                 \n");
10219             MrBayesPrint ("   Currently defined calibrations:                                               \n");
10220             MrBayesPrint ("                                                                                 \n");
10221             MrBayesPrint ("   Node name                Type       Calibration                               \n");
10222             MrBayesPrint ("   ------------------------------------------------------------------            \n");       
10223             for (i=0; i<numTaxa+numDefinedConstraints; i++)
10224                 {
10225                 if (i<numTaxa)
10226                     calibrationPtr = &tipCalibration[i];
10227                 else
10228                     calibrationPtr = &nodeCalibration[i-numTaxa];
10229                 if (calibrationPtr != NULL && calibrationPtr->prior != unconstrained)
10230                     {
10231                     if (i<numTaxa)
10232                         strncpy (tempString, taxaNames[i], 22);
10233                     else
10234                         strncpy (tempString, constraintNames[i-numTaxa], 22);
10235                     if (i<numTaxa)
10236                         MrBayesPrint ("   %-22.22s   Terminal   %s\n", tempString, calibrationPtr->name);
10237                     else
10238                         MrBayesPrint ("   %-22.22s   Interior   %s\n", tempString, calibrationPtr->name);
10239                     }
10240                 }
10241             }
10242         MrBayesPrint ("                                                                                 \n");
10243         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10244         }
10245     else if (!strcmp(helpTkn, "Showmodel"))
10246         {
10247         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10248         MrBayesPrint ("   Showmodel                                                                     \n");
10249         MrBayesPrint ("                                                                                 \n");
10250         MrBayesPrint ("   This command shows the current model settings. The correct usage is           \n");
10251         MrBayesPrint ("                                                                                 \n");
10252         MrBayesPrint ("      showmodel                                                                  \n");
10253         MrBayesPrint ("                                                                                 \n");
10254         MrBayesPrint ("   After typing \"showmodel\", the modelling assumptions are shown on a          \n");
10255         MrBayesPrint ("   partition-by-partition basis.                                                 \n");
10256         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10257         }
10258     else if (!strcmp(helpTkn, "Execute"))
10259         {
10260         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10261         MrBayesPrint ("   Execute                                                                       \n");
10262         MrBayesPrint ("                                                                                 \n");
10263         MrBayesPrint ("   This command executes a file called <file name>. The correct usage is:        \n");
10264         MrBayesPrint ("                                                                                 \n");
10265         MrBayesPrint ("      execute <file name>                                                        \n");
10266         MrBayesPrint ("                                                                                 \n");
10267         MrBayesPrint ("   For example,                                                                  \n");
10268         MrBayesPrint ("                                                                                 \n");
10269         MrBayesPrint ("      execute replicase.nex                                                      \n");
10270         MrBayesPrint ("                                                                                 \n");
10271         MrBayesPrint ("   would execute the file named \"replicase.nex\". This file must be in the      \n");
10272         MrBayesPrint ("   same directory as the executable.                                             \n");
10273         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10274         }
10275     else if (!strcmp(helpTkn, "Lset"))
10276         {
10277         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10278         MrBayesPrint ("   Lset                                                                          \n");
10279         MrBayesPrint ("                                                                                 \n");
10280         MrBayesPrint ("   This command sets the parameters of the likelihood model. The likelihood      \n");
10281         MrBayesPrint ("   function is the probability of observing the data conditional on the phylo-   \n");
10282         MrBayesPrint ("   genetic model. In order to calculate the likelihood, you must assume a        \n");
10283         MrBayesPrint ("   model of character change. This command lets you tailor the biological        \n");
10284         MrBayesPrint ("   assumptions made in the phylogenetic model. The correct usage is              \n");
10285         MrBayesPrint ("                                                                                 \n");
10286         MrBayesPrint ("      lset <parameter>=<option> ... <parameter>=<option>                         \n");
10287         MrBayesPrint ("                                                                                 \n");
10288         MrBayesPrint ("   For example, \"lset nst=6 rates=gamma\" would set the model to a general      \n");
10289         MrBayesPrint ("   model of DNA substition (the GTR) with gamma-distributed rate variation       \n");
10290         MrBayesPrint ("   across sites.                                                                 \n");
10291         MrBayesPrint ("                                                                                 \n");
10292         MrBayesPrint ("   Options:                                                                      \n");
10293         MrBayesPrint ("                                                                                 \n");
10294         MrBayesPrint ("   Applyto   -- This option allows you to apply the lset commands to specific    \n");
10295         MrBayesPrint ("                partitions. This command should be the first in the list of      \n");
10296         MrBayesPrint ("                commands specified in lset. Moreover, it only makes sense to     \n");
10297         MrBayesPrint ("                be using this command if the data have been partitioned. A       \n");
10298         MrBayesPrint ("                default partition is set on execution of a matrix. If the data   \n");
10299         MrBayesPrint ("                are homogeneous (i.e., all of the same data type), then this     \n");
10300         MrBayesPrint ("                partition will not subdivide the characters. Up to 30 other      \n");
10301         MrBayesPrint ("                partitions can be defined, and you can switch among them using   \n");
10302         MrBayesPrint ("                \"set partition=<partition name>\". Now, you may want to         \n");
10303         MrBayesPrint ("                specify different models to different partitions of the data.    \n");
10304         MrBayesPrint ("                Applyto allows you to do this. For example, say you have         \n");
10305         MrBayesPrint ("                partitioned the data by codon position, and you want to apply    \n");
10306         MrBayesPrint ("                a nst=2 model to the first two partitions and nst=6 to the       \n");
10307         MrBayesPrint ("                last. This could be implemented in two uses of lset:             \n");
10308         MrBayesPrint ("                                                                                 \n");
10309         MrBayesPrint ("                   lset applyto=(1,2) nst=2                                      \n");
10310         MrBayesPrint ("                                                                                 \n");
10311         MrBayesPrint ("                   lset applyto=(3) nst=6                                        \n");
10312         MrBayesPrint ("                                                                                 \n");
10313         MrBayesPrint ("                The first applies the parameters after \"applyto\" to the        \n");
10314         MrBayesPrint ("                first and second partitions. The second lset applies nst=6       \n");
10315         MrBayesPrint ("                to the third partition. You can also use applyto=(all), which    \n");
10316         MrBayesPrint ("                attempts to apply the parameter settings to all of the data      \n");
10317         MrBayesPrint ("                partitions. Importantly, if the option is not consistent with    \n");
10318         MrBayesPrint ("                the data in the partition, the program will not apply the        \n");
10319         MrBayesPrint ("                lset option to that partition.                                   \n");
10320         MrBayesPrint ("   Nucmodel  -- This specifies the general form of the nucleotide substitution   \n");
10321         MrBayesPrint ("                model. The options are \"4by4\" [the standard model of DNA       \n");
10322         MrBayesPrint ("                substitution in which there are only four states (A,C,G,T/U)],   \n");
10323         MrBayesPrint ("                \"doublet\" (a model appropriate for modelling the stem regions  \n");
10324         MrBayesPrint ("                of ribosomal genes where the state space is the 16 doublets of   \n");
10325         MrBayesPrint ("                nucleotides), \"codon\" (the substitution model is expanded      \n");
10326         MrBayesPrint ("                around triplets of nucleotides--a codon), and \"Protein\"        \n");
10327         MrBayesPrint ("                (triplets of nucleotides are translated to amino acids, which    \n");
10328         MrBayesPrint ("                form the basis of the substitution model).                       \n");
10329         MrBayesPrint ("   Nst       -- Sets the number of substitution types: \"1\" constrains all of   \n");
10330         MrBayesPrint ("                the rates to be the same (e.g., a JC69 or F81 model); \"2\" all- \n");
10331         MrBayesPrint ("                ows transitions and transversions to have potentially different  \n");
10332         MrBayesPrint ("                rates (e.g., a K80 or HKY85 model); \"6\" allows all rates to    \n");
10333         MrBayesPrint ("                be different, subject to the constraint of time-reversibility    \n");
10334         MrBayesPrint ("                (e.g., a GTR model). Finally, 'nst' can be set to 'mixed', which \n");
10335         MrBayesPrint ("                results in the Markov chain sampling over the space of all poss- \n");
10336         MrBayesPrint ("                ible reversible substitution models, including the GTR model and \n");
10337         MrBayesPrint ("                all models that can be derived from it model by grouping the six \n");
10338         MrBayesPrint ("                rates in various combinations. This includes all the named models\n");
10339         MrBayesPrint ("                above and a large number of others, with or without name.        \n");
10340         MrBayesPrint ("   Code      -- Enforces the use of a particular genetic code. The default       \n");
10341         MrBayesPrint ("                is the universal code. Other options include \"vertmt\" for      \n");
10342         MrBayesPrint ("                vertebrate mitocondrial, \"invermt\", \"mycoplasma\", \"yeast\", \n");
10343         MrBayesPrint ("                \"ciliate\", \"echinoderm\", \"euplotid\", and \"metmt\" (for    \n");
10344         MrBayesPrint ("                metazoan mitochondrial except vertebrates).                      \n");
10345         MrBayesPrint ("   Ploidy    -- Specifies the ploidy of the organism. Options are \"Haploid\",   \n");
10346         MrBayesPrint ("                \"Diploid\" or \"Zlinked\". This option is used when a coalescent\n");
10347         MrBayesPrint ("                prior is used on trees.                                          \n");
10348         MrBayesPrint ("   Rates     -- Sets the model for among-site rate variation. In general, the    \n");
10349         MrBayesPrint ("                rate at a site is considered to be an unknown random variable.   \n");
10350         MrBayesPrint ("                The valid options are:                                           \n");
10351         MrBayesPrint ("                * equal    -- No rate variation across sites.                    \n");
10352         MrBayesPrint ("                * gamma    -- Gamma-distributed rates across sites. The rate     \n");
10353         MrBayesPrint ("                              at a site is drawn from a gamma distribution.      \n");
10354         MrBayesPrint ("                              The gamma distribution has a single parameter      \n");
10355         MrBayesPrint ("                              that describes how much rates vary.                \n");
10356         MrBayesPrint ("                * lnorm    -- Log Normal-distributed rates across sites. The     \n");
10357         MrBayesPrint ("                              rate at a site is drawn from a lognormal           \n");
10358         MrBayesPrint ("                              distribution. the lognormal distribiton has a      \n");
10359         MrBayesPrint ("                              single parameter, sigma (SD) that describes how    \n");
10360         MrBayesPrint ("                              much rates vary (mean fixed to log(1.0) == 0.0.    \n");
10361         MrBayesPrint ("                * adgamma  -- Autocorrelated rates across sites. The marg-       \n");
10362         MrBayesPrint ("                              inal rate distribution is gamma, but adjacent      \n");
10363         MrBayesPrint ("                              sites have correlated rates.                       \n");
10364         MrBayesPrint ("                * propinv  -- A proportion of the sites are invariable.          \n");
10365         MrBayesPrint ("                * invgamma -- A proportion of the sites are invariable while     \n");
10366         MrBayesPrint ("                              the rate for the remaining sites are drawn from    \n");
10367         MrBayesPrint ("                              a gamma distribution.                              \n");
10368         MrBayesPrint ("                Note that MrBayes versions 2.0 and earlier supported options     \n");
10369         MrBayesPrint ("                that allowed site specific rates (e.g., ssgamma). In versions    \n");
10370         MrBayesPrint ("                3.0 and later, site specific rates are allowed, but set using    \n");
10371         MrBayesPrint ("                the 'prset ratepr' command for each partition.                   \n");
10372         MrBayesPrint ("   Ngammacat -- Sets the number of rate categories for the gamma distribution.   \n");
10373         MrBayesPrint ("                The gamma distribution is continuous. However, it is virtually   \n");
10374         MrBayesPrint ("                impossible to calculate likelihoods under the continuous gamma   \n");
10375         MrBayesPrint ("                distribution. Hence, an approximation to the continuous gamma    \n");
10376         MrBayesPrint ("                is used; the gamma distribution is broken into ncat categories   \n");
10377         MrBayesPrint ("                of equal weight (1/ncat). The mean rate for each category rep-   \n");
10378         MrBayesPrint ("                resents the rate for the entire cateogry. This option allows     \n");
10379         MrBayesPrint ("                you to specify how many rate categories to use when approx-      \n");
10380         MrBayesPrint ("                imating the gamma. The approximation is better as ncat is inc-   \n");
10381         MrBayesPrint ("                reased. In practice, \"ncat=4\" does a reasonable job of         \n");
10382         MrBayesPrint ("                approximating the continuous gamma.                              \n");
10383         MrBayesPrint ("                It is also used to set the number of rate categories for the     \n");
10384         MrBayesPrint ("                lognormal distribution to avoid changing too much of the code,   \n");
10385         MrBayesPrint ("                although the name is bad (should add Nlnormcat in future).       \n");
10386 #if 0
10387         /* Temporarily disable this because of conflict with likelihood calculators. It should be renamed to samplerates when reintroduced. */
10388         MrBayesPrint ("   Usegibbs  -- Specifies whether site probabilities under the discrete gamma    \n");
10389         MrBayesPrint ("                model of rate variation across sites will be summed across rate  \n");
10390         MrBayesPrint ("                categories ('Usegibbs=No') or sampled using a Gibbs sampler      \n");
10391         MrBayesPrint ("                ('Usegibbs=Yes'). The Gibbs sampling approach is much faster and \n");
10392         MrBayesPrint ("                requires less memory but the likelihood of the sampled points    \n");
10393         MrBayesPrint ("                will be considerably higher than with the standard approach of   \n");
10394         MrBayesPrint ("                summing probabilities, so you need to be aware of this when com- \n");
10395         MrBayesPrint ("                paring your results with those you obtain with other programs.   \n");
10396         MrBayesPrint ("                Assume that you are using n rate categories in your discrete     \n");
10397         MrBayesPrint ("                gamma distribution. Then the Gibbs approach is up to n times     \n");
10398         MrBayesPrint ("                faster and requires 1/n as much memory as the standard method.   \n");
10399         MrBayesPrint ("                Unfortunately, the state space also becomes larger so the chain  \n");
10400         MrBayesPrint ("                may need more time to converge. The approach should work best    \n");
10401         MrBayesPrint ("                for large trees, where the uncertainty concerning the best rate  \n");
10402         MrBayesPrint ("                category for each site is negligible. Gibbs sampling cannot be   \n");
10403         MrBayesPrint ("                used for the autocorrelated discrete gamma model, for standard   \n");
10404         MrBayesPrint ("                data, or for restriction data. Also, MrBayes will not use Gibbs  \n");
10405         MrBayesPrint ("                sampling when you want to infer site rates.                      \n");
10406         MrBayesPrint ("   Gibbsfreq -- Sets the frequency with which the rate categories of the discrete\n");
10407         MrBayesPrint ("                gamma will be Gibbs sampled. In practice, we have found that a   \n");
10408         MrBayesPrint ("                resampling frequency of every 100 MCMC generations works well for\n");
10409         MrBayesPrint ("                reasonably long runs. The more frequent the Gibbs sampling, the  \n");
10410         MrBayesPrint ("                slower the Gibbs sampling approach will be. If you have k rate   \n");
10411         MrBayesPrint ("                categories and Gibbs sample them every n generations, then the   \n");
10412         MrBayesPrint ("                time it takes to complete n generations will roughly be propor-  \n");
10413         MrBayesPrint ("                tional to n+k. Compare this with the traditional approach of     \n");
10414         MrBayesPrint ("                summing across the n rate categories in every generation, which  \n");
10415         MrBayesPrint ("                requires time proportional to n*k. In practice, however, the     \n");
10416         MrBayesPrint ("                speed difference is not quite as large as this.                  \n");
10417 #endif
10418         MrBayesPrint ("   Nbetacat  -- Sets the number of rate categories for the beta distribution.    \n");
10419         MrBayesPrint ("                A symmetric beta distribution is used to model the stationary    \n");
10420         MrBayesPrint ("                frequencies when morphological data are used. This option        \n");
10421         MrBayesPrint ("                specifies how well the beta distribution will be approximated.   \n");
10422         MrBayesPrint ("   Omegavar  -- Allows the nonsynonymous/synonymous rate ratio (omega) to vary   \n");
10423         MrBayesPrint ("                across codons. Ny98 assumes that there are three classes, with   \n");
10424         MrBayesPrint ("                potentially different omega values (omega1, omega2, omega3):     \n");
10425         MrBayesPrint ("                omega2 = 1; 0 < omega1 < 1; and omega3 > 1. Like the Ny98 model, \n");
10426         MrBayesPrint ("                the M3 model has three omega classes. However, their values are  \n");
10427         MrBayesPrint ("                less constrained, with omega1 < omega2 < omega3. The default     \n");
10428         MrBayesPrint ("                (omegavar = equal) has no variation on omega across sites.       \n");
10429         MrBayesPrint ("   Covarion  -- This forces the use of a covarion-like model of substitution     \n");
10430         MrBayesPrint ("                for nucleotide or amino acid data. The valid options are \"yes\" \n");
10431         MrBayesPrint ("                and \"no\". The covarion model allows the rate at a site to      \n");
10432         MrBayesPrint ("                change over its evolutionary history. Specifically, the site     \n");
10433         MrBayesPrint ("                is either on or off. When it is off, no substitutions are poss-  \n");
10434         MrBayesPrint ("                ible. When the process is on, substitutions occur according to   \n");
10435         MrBayesPrint ("                a specified substitution model (specified using the other        \n");
10436         MrBayesPrint ("                lset options).                                                   \n");
10437         MrBayesPrint ("   Coding    -- This specifies how characters were sampled. If all site patterns \n");
10438         MrBayesPrint ("                had the possibility of being sampled, then \"All\" should be     \n");
10439         MrBayesPrint ("                specified (the default). Otherwise \"Variable\" (only variable   \n");
10440         MrBayesPrint ("                characters had the possibility of being sampled), \"Informative\"\n");
10441         MrBayesPrint ("                (only parsimony informative characters has the possibility of    \n");
10442         MrBayesPrint ("                being sampled), \"Nosingletons\" (characters which are constant  \n");
10443         MrBayesPrint ("                in all but one taxon were not sampled), \"Noabsencesites\" (char-\n");
10444         MrBayesPrint ("                acters for which all taxa were coded as absent were not sampled),\n");
10445         MrBayesPrint ("                \"Nopresencesites\" (characters for which all taxa were coded as \n");
10446         MrBayesPrint ("                present were not sampled). \"All\" works for all data types.     \n");
10447         MrBayesPrint ("                However, the others only work for morphological (All/Variable/   \n");
10448         MrBayesPrint ("                Informative/Nosingletons) or restriction site (All/Variable/     \n");
10449         MrBayesPrint ("                Informative/Nosingletons/Noabsencesites/Nopresencesites/         \n");
10450         MrBayesPrint ("                Nosingletonpresence/Nosingletonabsence) data.                    \n");
10451         MrBayesPrint ("   Parsmodel -- This forces calculation under the so-called parsimony model      \n");
10452         MrBayesPrint ("                described by Tuffley and Steel (1998). The options are \"yes\"   \n");
10453         MrBayesPrint ("                or \"no\". Note that the biological assumptions of this model    \n");
10454         MrBayesPrint ("                are anything but parsimonious. In fact, this model assumes many  \n");
10455         MrBayesPrint ("                more parameters than the next most complicated model implemented \n");
10456         MrBayesPrint ("                in this program. If you really believe that the parsimony model  \n");
10457         MrBayesPrint ("                makes the biological assumptions described by Tuffley and Steel, \n");
10458         MrBayesPrint ("                then the parsimony method is miss-named.                         \n");
10459     /*  MrBayesPrint ("   Augment   -- This allows the chain to consider the missing entries of         \n");
10460         MrBayesPrint ("                the data matrix as random variables. A Gibbs sampler is          \n");
10461         MrBayesPrint ("                used to sample states.                                           \n"); */
10462         MrBayesPrint ("                                                                                 \n");
10463         if (numCurrentDivisions == 0)
10464             tempInt = 1;
10465         else
10466             tempInt = numCurrentDivisions;
10467         for (i=0; i<tempInt; i++)
10468             {
10469             if (numCurrentDivisions == 0)
10470                 {
10471                 MrBayesPrint ("   Default model settings:                                                       \n");
10472                 mp = &defaultModel;
10473                 }
10474             else
10475                 {
10476                 MrBayesPrint ("   Model settings for partition %d:                                              \n", i+1);
10477                 mp = &modelParams[i];
10478                 }
10479             MrBayesPrint ("                                                                                 \n");
10480             MrBayesPrint ("   Parameter    Options                               Current Setting            \n");
10481             MrBayesPrint ("   ------------------------------------------------------------------            \n");       
10482             MrBayesPrint ("   Nucmodel     4by4/Doublet/Codon/Protein              %s                       \n", mp->nucModel);
10483             MrBayesPrint ("   Nst          1/2/6/Mixed                             %s                       \n", mp->nst);
10484             MrBayesPrint ("   Code         Universal/Vertmt/Invermt/Yeast/Mycoplasma/                       \n");
10485             MrBayesPrint ("                Ciliate/Echinoderm/Euplotid/Metmt       %s                       \n", mp->geneticCode);
10486             MrBayesPrint ("   Ploidy       Haploid/Diploid/Zlinked                 %s                       \n", mp->ploidy);
10487             MrBayesPrint ("   Rates        Equal/Gamma/LNorm/Propinv/                                       \n");
10488             MrBayesPrint ("                Invgamma/Adgamma                        %s                       \n", mp->ratesModel);
10489             MrBayesPrint ("   Ngammacat    <number>                                %d                       \n", mp->numGammaCats);
10490 #if 0
10491 /* Temporarily disable this because of conflict with likelihood calculators. It should be renamed to samplerates when reintroduced. */
10492             MrBayesPrint ("   Usegibbs     Yes/No                                  %s                       \n", mp->useGibbs);
10493             MrBayesPrint ("   Gibbsfreq    <number>                                %d                       \n", mp->gibbsFreq);
10494 #endif
10495             MrBayesPrint ("   Nbetacat     <number>                                %d                       \n", mp->numBetaCats);
10496             MrBayesPrint ("   Omegavar     Equal/Ny98/M3                           %s                       \n", mp->omegaVar);
10497             MrBayesPrint ("   Covarion     No/Yes                                  %s                       \n", mp->covarionModel);
10498             MrBayesPrint ("   Coding       All/Variable/Informative/Nosingletons                            \n");
10499             MrBayesPrint ("                Noabsencesites/Nopresencesites/                                  \n");
10500             MrBayesPrint ("                Nosingletonabsence/Nosingletonpresence  %s                       \n", mp->codingString);
10501             MrBayesPrint ("   Parsmodel    No/Yes                                  %s                       \n", mp->parsModel);
10502         /*  MrBayesPrint ("   Augment      No/Yes                                  %s                       \n", mp->augmentData); */
10503             MrBayesPrint ("   ------------------------------------------------------------------            \n");       
10504             MrBayesPrint ("                                                                                 \n");
10505             }
10506         }
10507     else if (!strcmp(helpTkn, "Prset"))
10508         {
10509         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
10510         MrBayesPrint ("   Prset                                                                         \n");
10511         MrBayesPrint ("                                                                                 \n");
10512         MrBayesPrint ("   This command sets the priors for the phylogenetic model. Remember that        \n");
10513         MrBayesPrint ("   in a Bayesian analysis, you must specify a prior probability distribution     \n");
10514         MrBayesPrint ("   for the parameters of the likelihood model. The prior distribution rep-       \n");
10515         MrBayesPrint ("   resents your prior beliefs about the parameter before observation of the      \n");
10516         MrBayesPrint ("   data. This command allows you to tailor your prior assumptions to a large     \n");
10517         MrBayesPrint ("   extent.                                                                       \n");
10518         MrBayesPrint ("                                                                                 \n");
10519         MrBayesPrint ("   Options:                                                                      \n");
10520         MrBayesPrint ("                                                                                 \n");
10521         MrBayesPrint ("   Applyto       -- This option allows you to apply the prset commands to        \n");
10522         MrBayesPrint ("                    specific partitions. This command should be the first        \n");
10523         MrBayesPrint ("                    in the list of commands specified in prset. Moreover, it     \n");
10524         MrBayesPrint ("                    only makes sense to be using this command if the data        \n");
10525         MrBayesPrint ("                    have been partitioned. A default partition is set on         \n");
10526         MrBayesPrint ("                    execution of a matrix. If the data are homogeneous           \n");
10527         MrBayesPrint ("                    (i.e., all of the same data type), then this partition       \n");
10528         MrBayesPrint ("                    will not subdivide the characters. Up to 30 other part-      \n");
10529         MrBayesPrint ("                    itions can be defined, and you can switch among them using   \n");
10530         MrBayesPrint ("                    \"set partition=<partition name>\". Now, you may want to     \n");
10531         MrBayesPrint ("                    specify different priors to different partitions of the      \n");
10532         MrBayesPrint ("                    data. Applyto allows you to do this. For example, say        \n");
10533         MrBayesPrint ("                    you have partitioned the data by codon position, and         \n");
10534         MrBayesPrint ("                    you want to fix the statefreqs to equal for the first two    \n");
10535         MrBayesPrint ("                    partitions but apply a flat Dirichlet prior to the state-    \n");
10536         MrBayesPrint ("                    freqs of the last. This could be implemented in two uses of  \n");
10537         MrBayesPrint ("                    prset:                                                       \n");
10538         MrBayesPrint ("                                                                                 \n");
10539         MrBayesPrint ("                       prset applyto=(1,2) statefreqs=fixed(equal)               \n");
10540         MrBayesPrint ("                                                                                 \n");
10541         MrBayesPrint ("                       prset applyto=(3) statefreqs=dirichlet(1,1,1,1)           \n");
10542         MrBayesPrint ("                                                                                 \n");
10543         MrBayesPrint ("                    The first applies the parameters after \"applyto\"           \n");
10544         MrBayesPrint ("                    to the first and second partitions. The second prset         \n");
10545         MrBayesPrint ("                    applies a flat Dirichlet to the third partition. You can     \n");
10546         MrBayesPrint ("                    also use applyto=(all), which attempts to apply the para-    \n");
10547         MrBayesPrint ("                    meter settings to all of the data partitions. Importantly,   \n");
10548         MrBayesPrint ("                    if the option is not consistent with the data in the part-   \n");
10549         MrBayesPrint ("                    ition, the program will not apply the prset option to        \n");
10550         MrBayesPrint ("                    that partition.                                              \n");
10551         MrBayesPrint ("   Tratiopr      -- This parameter sets the prior for the transition/trans-      \n");
10552         MrBayesPrint ("                    version rate ratio (tratio). The options are:                \n");
10553         MrBayesPrint ("                                                                                 \n");
10554         MrBayesPrint ("                       prset tratiopr = beta(<number>, <number>)                 \n");
10555         MrBayesPrint ("                       prset tratiopr = fixed(<number>)                          \n");
10556         MrBayesPrint ("                                                                                 \n");
10557         MrBayesPrint ("                    The program assumes that the transition and transversion     \n");
10558         MrBayesPrint ("                    rates are independent gamma-distributed random variables     \n");
10559         MrBayesPrint ("                    with the same scale parameter when beta is selected. If you  \n");
10560         MrBayesPrint ("                    want a diffuse prior that puts equal emphasis on transition/ \n");
10561         MrBayesPrint ("                    transversion rate ratios above 1.0 and below 1.0, then use a \n");
10562         MrBayesPrint ("                    flat Beta, beta(1,1), which is the default. If you wish to   \n");
10563         MrBayesPrint ("                    concentrate this distribution more in the equal-rates region,\n");
10564         MrBayesPrint ("                    then use a prior of the type beta(x,x), where the magnitude  \n");
10565         MrBayesPrint ("                    of x determines how much the prior is concentrated in the    \n");
10566         MrBayesPrint ("                    equal rates region. For instance, a beta(20,20) puts more    \n");
10567         MrBayesPrint ("                    probability on rate ratios close to 1.0 than a beta(1,1). If \n");
10568         MrBayesPrint ("                    you think it is likely that the transition/transversion rate \n");
10569         MrBayesPrint ("                    ratio is 2.0, you can use a prior of the type beta(2x,x),    \n");
10570         MrBayesPrint ("                    where x determines how strongly the prior is concentrated on \n");
10571         MrBayesPrint ("                    tratio values near 2.0. For instance, a beta(2,1) is much    \n");
10572         MrBayesPrint ("                    more diffuse than a beta(80,40) but both have the expected   \n");
10573         MrBayesPrint ("                    tratio 2.0 in the absence of data. The parameters of the     \n");
10574         MrBayesPrint ("                    Beta can be interpreted as counts: if you have observed x    \n");
10575         MrBayesPrint ("                    transitions and y transversions, then a beta(x+1,y+1) is a   \n");
10576         MrBayesPrint ("                    good representation of this information. The fixed option    \n");
10577         MrBayesPrint ("                    allows you to fix the tratio to a particular value.          \n");
10578         MrBayesPrint ("   Revmatpr      -- This parameter sets the prior for the substitution rates     \n");
10579         MrBayesPrint ("                    of the GTR model for nucleotide data. The options are:       \n");
10580         MrBayesPrint ("                                                                                 \n");
10581         MrBayesPrint ("                       prset revmatpr = dirichlet(<number>,<number>,...,<number>)\n");
10582         MrBayesPrint ("                       prset revmatpr = fixed(<number>,<number>,...,<number>)    \n");
10583         MrBayesPrint ("                                                                                 \n");
10584         MrBayesPrint ("                    The program assumes that the six substitution rates          \n");
10585         MrBayesPrint ("                    are independent gamma-distributed random variables with the  \n");
10586         MrBayesPrint ("                    same scale parameter when dirichlet is selected. The six     \n");
10587         MrBayesPrint ("                    numbers in brackets each corresponds to a particular substi- \n");
10588         MrBayesPrint ("                    tution type. Together, they determine the shape of the prior.\n");
10589         MrBayesPrint ("                    The six rates are in the order A<->C, A<->G, A<->T, C<->G,   \n");
10590         MrBayesPrint ("                    C<->T, and G<->T. If you want an uninformative prior you can \n");
10591         MrBayesPrint ("                    use dirichlet(1,1,1,1,1,1), also referred to as a 'flat'     \n");
10592         MrBayesPrint ("                    Dirichlet. This is the default setting. If you wish a prior  \n");
10593         MrBayesPrint ("                    where the C<->T rate is 5 times and the A<->G rate 2 times   \n");
10594         MrBayesPrint ("                    higher, on average, than the transversion rates, which are   \n");
10595         MrBayesPrint ("                    all the same, then you should use a prior of the form        \n");
10596         MrBayesPrint ("                    dirichlet(x,2x,x,x,5x,x), where x determines how much the    \n");
10597         MrBayesPrint ("                    prior is focused on these particular rates. For more info,   \n");
10598         MrBayesPrint ("                    see tratiopr. The fixed option allows you to fix the substi- \n");
10599         MrBayesPrint ("                    tution rates to particular values.                           \n");
10600         MrBayesPrint ("   Revratepr     -- This parameter sets the prior for each substitution rate of  \n");
10601         MrBayesPrint ("                    the GTR model subspace when 'nst' is set to 'mixed' (see the \n");
10602         MrBayesPrint ("                    'lset' command). The only option is                          \n");
10603         MrBayesPrint ("                                                                                 \n");
10604         MrBayesPrint ("                       prset revratepr = symdir(<number>)                        \n");
10605         MrBayesPrint ("                                                                                 \n");
10606         MrBayesPrint ("                    which will associate each independent rate in the rate matrix\n");
10607         MrBayesPrint ("                    with a modified symmetric Dirichlet prior, where a singleton \n");
10608         MrBayesPrint ("                    rate has the specified alpha parameter, while a rate that    \n");
10609         MrBayesPrint ("                    applies to n pairwise substitution types has an alpha that is\n");
10610         MrBayesPrint ("                    n times the specified number. The higher the specified num-  \n");
10611         MrBayesPrint ("                    ber, the more focused the prior will be on equal rates. The  \n");
10612         MrBayesPrint ("                    default value is 1, which gives an effect similar to a flat  \n");
10613         MrBayesPrint ("                    Dirichlet.                                                   \n");
10614         MrBayesPrint ("   Aamodelpr     -- This parameter sets the rate matrix for amino acid data.     \n");
10615         MrBayesPrint ("                    You can either fix the model by specifying aamodelpr=fixed   \n");
10616         MrBayesPrint ("                    (<model name>), where <model name> is 'poisson' (a glorified \n");
10617         MrBayesPrint ("                    Jukes-Cantor model), 'jones', 'dayhoff', 'mtrev', 'mtmam',   \n");
10618         MrBayesPrint ("                    'wag', 'rtrev', 'cprev', 'vt', 'blosum', 'lg', 'equalin'     \n");
10619         MrBayesPrint ("                    (a glorified Felsenstein 1981 model), or 'gtr'. You can also \n");
10620         MrBayesPrint ("                    average over the first ten models by specifying aamodelpr=   \n");
10621         MrBayesPrint ("                    mixed. If you do so, the Markov chain will sample each model \n");
10622         MrBayesPrint ("                    according to its probability. The sampled model is reported  \n");
10623         MrBayesPrint ("                    as an index: poisson(0), jones(1), dayhoff(2), mtrev(3),     \n");
10624         MrBayesPrint ("                    mtmam(4), wag(5), rtrev(6), cprev(7), vt(8), or blosum(9).   \n");
10625         MrBayesPrint ("                    The 'Sump' command summarizes the MCMC samples and calculates\n");
10626         MrBayesPrint ("                    the posterior probability estimate for each of these models. \n");
10627         MrBayesPrint ("   Aarevmatpr    -- This parameter sets the prior for the substitution rates     \n");
10628         MrBayesPrint ("                    of the GTR model for amino acid data. The options are:       \n");
10629         MrBayesPrint ("                                                                                 \n");
10630         MrBayesPrint ("                       prset aarevmatpr = dirichlet(<number>,<number>,...,<number>)\n");
10631         MrBayesPrint ("                       prset aarevmatpr = fixed(<number>,<number>,...,<number>)  \n");
10632         MrBayesPrint ("                                                                                 \n");
10633         MrBayesPrint ("                    The options are the same as those for 'Revmatpr' except that \n");
10634         MrBayesPrint ("                    they are defined over the 190 rates of the time-reversible   \n");
10635         MrBayesPrint ("                    GTR model for amino acids instead of over the 6 rates of the \n");
10636         MrBayesPrint ("                    GTR model for nucleotides. The rates are in the order A<->R, \n");
10637         MrBayesPrint ("                    A<->N, etc to Y<->V. In other words, amino acids are listed  \n");
10638         MrBayesPrint ("                    in alphabetic order based on their full name. The first amino\n");
10639         MrBayesPrint ("                    acid (Alanine) is then combined in turn with all amino acids \n");
10640         MrBayesPrint ("                    following it in the list, starting with amino acid 2 (Argi-  \n");
10641         MrBayesPrint ("                    nine) and finishing with amino acid 20 (Valine). The second  \n");
10642         MrBayesPrint ("                    amino acid (Arginine) is then combined in turn with all amino\n");
10643         MrBayesPrint ("                    acids following it, starting with amino acid 3 (Asparagine)  \n");
10644         MrBayesPrint ("                    and finishing with amino acid 20 (Valine), and so on.        \n");
10645         MrBayesPrint ("   Omegapr       -- This parameter specifies the prior on the nonsynonymous/     \n");
10646         MrBayesPrint ("                    synonymous rate ratio. The options are:                      \n");
10647         MrBayesPrint ("                                                                                 \n");
10648         MrBayesPrint ("                       prset omegapr = dirichlet(<number>,<number>)              \n");
10649         MrBayesPrint ("                       prset omegapr = fixed(<number>)                           \n");
10650         MrBayesPrint ("                                                                                 \n");
10651         MrBayesPrint ("                    This parameter is only in effect if the nucleotide sub-      \n");
10652         MrBayesPrint ("                    stitution model is set to codon using the lset command       \n");
10653         MrBayesPrint ("                    (lset nucmodel=codon). Moreover, it only applies to the      \n");
10654         MrBayesPrint ("                    case when there is no variation in omega across sites (i.e., \n");
10655         MrBayesPrint ("                    \"lset omegavar=equal\").                                    \n");
10656         MrBayesPrint ("   Ny98omega1pr  -- This parameter specifies the prior on the nonsynonymous/     \n");
10657         MrBayesPrint ("                    synonymous rate ratio for sites under purifying selection.   \n");
10658         MrBayesPrint ("                    The options are:                                             \n");
10659         MrBayesPrint ("                                                                                 \n");
10660         MrBayesPrint ("                       prset Ny98omega1pr = beta(<number>,<number>)              \n");
10661         MrBayesPrint ("                       prset Ny98omega1pr = fixed(<number>)                      \n");
10662         MrBayesPrint ("                                                                                 \n");
10663         MrBayesPrint ("                    This parameter is only in effect if the nucleotide sub-      \n");
10664         MrBayesPrint ("                    stitution model is set to codon using the lset command       \n");
10665         MrBayesPrint ("                    (lset nucmodel=codon). Moreover, it only applies to the      \n");
10666         MrBayesPrint ("                    case where omega varies across sites using the model of      \n");
10667         MrBayesPrint ("                    Nielsen and Yang (1998) (i.e., \"lset omegavar=ny98\"). If   \n");
10668         MrBayesPrint ("                    fixing the parameter, you must specify a number between      \n");
10669         MrBayesPrint ("                    0 and 1.                                                     \n");
10670         MrBayesPrint ("   Ny98omega3pr  -- This parameter specifies the prior on the nonsynonymous/     \n");
10671         MrBayesPrint ("                    synonymous rate ratio for positively selected sites. The     \n");
10672         MrBayesPrint ("                    options are:                                                 \n");
10673         MrBayesPrint ("                                                                                 \n");
10674         MrBayesPrint ("                       prset Ny98omega3pr = uniform(<number>,<number>)           \n");
10675         MrBayesPrint ("                       prset Ny98omega3pr = exponential(<number>)                \n");
10676         MrBayesPrint ("                       prset Ny98omega3pr = fixed(<number>)                      \n");
10677         MrBayesPrint ("                                                                                 \n");
10678         MrBayesPrint ("                    This parameter is only in effect if the nucleotide sub-      \n");
10679         MrBayesPrint ("                    stitution model is set to codon using the lset command       \n");
10680         MrBayesPrint ("                    (lset nucmodel=codon). Moreover, it only applies to the      \n");
10681         MrBayesPrint ("                    case where omega varies across sites according to the        \n");
10682         MrBayesPrint ("                    NY98 model. Note that if the NY98 model is specified         \n");
10683         MrBayesPrint ("                    that this parameter must be greater than 1, so you should    \n");
10684         MrBayesPrint ("                    not specify a uniform(0,10) prior, for example.              \n");
10685         MrBayesPrint ("   M3omegapr     -- This parameter specifies the prior on the nonsynonymous/     \n");
10686         MrBayesPrint ("                    synonymous rate ratios for all three classes of sites for    \n");
10687         MrBayesPrint ("                    the M3 model. The options are:                               \n");
10688         MrBayesPrint ("                                                                                 \n");
10689         MrBayesPrint ("                       prset M3omegapr = exponential                             \n");
10690         MrBayesPrint ("                       prset M3omegapr = fixed(<number>,<number>,<number>)       \n");
10691         MrBayesPrint ("                                                                                 \n");
10692         MrBayesPrint ("                    This parameter is only in effect if the nucleotide sub-      \n");
10693         MrBayesPrint ("                    stitution model is set to codon using the lset command       \n");
10694         MrBayesPrint ("                    (lset nucmodel=codon). Moreover, it only applies to the      \n");
10695         MrBayesPrint ("                    case where omega varies across sites using the M3 model of   \n");
10696         MrBayesPrint ("                    Yang et al. (2000) (i.e., \"lset omegavar=M3\"). Under the   \n");
10697         MrBayesPrint ("                    exponential prior, the four rates (dN1, dN2, dN3, and dS)    \n");
10698         MrBayesPrint ("                    are all considered to be independent draws from the same     \n");
10699         MrBayesPrint ("                    exponential distribution (the parameter of the exponential   \n");
10700         MrBayesPrint ("                    does not matter, and so you don't need to specify it). The   \n");
10701         MrBayesPrint ("                    rates dN1, dN2, and dN3 are taken to be the order statistics \n");
10702         MrBayesPrint ("                    with dN1 < dN2 < dN3. These three rates are all scaled to    \n");
10703         MrBayesPrint ("                    the same synonymous rate, dS. The other option is to simply  \n");
10704         MrBayesPrint ("                    fix the three rate ratios to some values.                    \n");
10705         MrBayesPrint ("   Codoncatfreqs -- This parameter specifies the prior on frequencies of sites   \n");
10706         MrBayesPrint ("                    under purifying, neutral, and positive selection. The        \n");
10707         MrBayesPrint ("                    options are:                                                 \n");
10708         MrBayesPrint ("                                                                                 \n");
10709         MrBayesPrint ("                       prset codoncatfreqs = dirichlet(<num>,<num>,<num>)        \n");
10710         MrBayesPrint ("                       prset codoncatfreqs = fixed(<number>,<number>,<number>)   \n");
10711         MrBayesPrint ("                                                                                 \n");
10712         MrBayesPrint ("                    This parameter is only in effect if the nucleotide sub-      \n");
10713         MrBayesPrint ("                    stitution model is set to codon using the lset command       \n");
10714         MrBayesPrint ("                    (lset nucmodel=codon). Moreover, it only applies to the      \n");
10715         MrBayesPrint ("                    case where omega varies across sites using the models of     \n");
10716         MrBayesPrint ("                    Nielsen and Yang (1998) (i.e., \"lset omegavar=ny98\")       \n");
10717         MrBayesPrint ("                    or Yang et al. (2000) (i.e., \"lset omegavar=M3\")           \n");
10718         MrBayesPrint ("                    Note that the sum of the three frequencies must be 1.        \n");
10719         MrBayesPrint ("   Statefreqpr   -- This parameter specifies the prior on the state freq-        \n");
10720         MrBayesPrint ("                    uencies. The options are:                                    \n");
10721         MrBayesPrint ("                                                                                 \n");
10722         MrBayesPrint ("                       prset statefreqpr = dirichlet(<number>)                   \n");
10723         MrBayesPrint ("                       prset statefreqpr = dirichlet(<number>,...,<number>)      \n");
10724         MrBayesPrint ("                       prset statefreqpr = fixed(equal)                          \n");
10725         MrBayesPrint ("                       prset statefreqpr = fixed(empirical)                      \n");
10726         MrBayesPrint ("                       prset statefreqpr = fixed(<number>,...,<number>)          \n");
10727         MrBayesPrint ("                                                                                 \n");
10728         MrBayesPrint ("                    For the dirichlet, you can specify either a single number    \n");
10729         MrBayesPrint ("                    or as many numbers as there are states. If you specify a     \n");
10730         MrBayesPrint ("                    single number, then the prior has all states equally         \n");
10731         MrBayesPrint ("                    probable with a variance related to the single parameter     \n");
10732         MrBayesPrint ("                    passed in.                                                   \n");
10733         MrBayesPrint ("   Shapepr       -- This parameter specifies the prior for the gamma/lnorm shape \n");
10734         MrBayesPrint ("                    parameter for among-site rate variation. The options are:    \n");
10735         MrBayesPrint ("                                                                                 \n");
10736         MrBayesPrint ("                       prset shapepr = uniform(<number>,<number>)                \n");
10737         MrBayesPrint ("                       prset shapepr = exponential(<number>)                     \n");
10738         MrBayesPrint ("                       prset shapepr = fixed(<number>)                           \n");
10739         MrBayesPrint ("                                                                                 \n");
10740         MrBayesPrint ("   Pinvarpr      -- This parameter specifies the prior for the proportion of     \n");
10741         MrBayesPrint ("                    invariable sites. The options are:                           \n");
10742         MrBayesPrint ("                                                                                 \n");
10743         MrBayesPrint ("                       prset pinvarpr = uniform(<number>,<number>)               \n");
10744         MrBayesPrint ("                       prset pinvarpr = fixed(<number>)                          \n");
10745         MrBayesPrint ("                                                                                 \n");
10746         MrBayesPrint ("                    Note that the valid range for the parameter is between 0     \n");
10747         MrBayesPrint ("                    and 1. Hence, \"prset pinvarpr=uniform(0,0.8)\" is valid     \n");
10748         MrBayesPrint ("                    while \"prset pinvarpr=uniform(0,10)\" is not. The def-      \n");
10749         MrBayesPrint ("                    ault setting is \"prset pinvarpr=uniform(0,1)\".             \n");
10750         MrBayesPrint ("   Ratecorrpr    -- This parameter specifies the prior for the autocorrelation   \n");
10751         MrBayesPrint ("                    parameter of the autocorrelated gamma distribution for       \n");
10752         MrBayesPrint ("                    among-site rate variation. The options are:                  \n");
10753         MrBayesPrint ("                                                                                 \n");
10754         MrBayesPrint ("                       prset ratecorrpr = uniform(<number>,<number>)             \n");
10755         MrBayesPrint ("                       prset ratecorrpr = fixed(<number>)                        \n");
10756         MrBayesPrint ("                                                                                 \n");
10757         MrBayesPrint ("                    Note that the valid range for the parameter is between -1    \n");
10758         MrBayesPrint ("                    and 1. Hence, \"prset ratecorrpr=uniform(-1,1)\" is valid    \n");
10759         MrBayesPrint ("                    while \"prset ratecorrpr=uniform(-11,10)\" is not. The       \n");
10760         MrBayesPrint ("                    default setting is \"prset ratecorrpr=uniform(-1,1)\".       \n");
10761         MrBayesPrint ("   Covswitchpr   -- This option sets the prior for the covarion switching        \n");
10762         MrBayesPrint ("                    rates. The options are:                                      \n");
10763         MrBayesPrint ("                                                                                 \n");
10764         MrBayesPrint ("                       prset covswitchpr = uniform(<number>,<number>)            \n");
10765         MrBayesPrint ("                       prset covswitchpr = exponential(<number>)                 \n");
10766         MrBayesPrint ("                       prset covswitchpr = fixed(<number>,<number>)              \n");
10767         MrBayesPrint ("                                                                                 \n");
10768         MrBayesPrint ("                    The covarion model has two rates: a rate from on to off      \n");
10769         MrBayesPrint ("                    and a rate from off to on. The rates are assumed to have     \n");
10770         MrBayesPrint ("                    independent priors that individually are either uniformly    \n");
10771         MrBayesPrint ("                    or exponentially distributed. The other option is to         \n");
10772         MrBayesPrint ("                    fix the switching rates, in which case you must specify      \n");
10773         MrBayesPrint ("                    both rates. (The first number is off->on and the second      \n");
10774         MrBayesPrint ("                    is on->off).                                                 \n");
10775         MrBayesPrint ("   Symdirihyperpr - This option sets the prior for the stationary frequencies    \n");
10776         MrBayesPrint ("                    of the states for morphological (standard) data. There can   \n");
10777         MrBayesPrint ("                    be as many as 10 states for standard data. However, the      \n");
10778         MrBayesPrint ("                    labelling of the states is somewhat arbitrary. For example,  \n");
10779         MrBayesPrint ("                    the state \"1\" for different characters does not have the   \n");
10780         MrBayesPrint ("                    same meaning. This is not true for DNA characters, for ex-   \n");
10781         MrBayesPrint ("                    ample, where a \"G\" has the same meaning across characters. \n");
10782         MrBayesPrint ("                    The fact that the labelling of morphological characters is   \n");
10783         MrBayesPrint ("                    arbitrary makes it difficult to allow unequal character-     \n");
10784         MrBayesPrint ("                    state frequencies. MrBayes gets around this problem by       \n");
10785         MrBayesPrint ("                    assuming that the states have a symmetric Dirichlet prior    \n");
10786         MrBayesPrint ("                    (i.e. all Dirichlet parameters are equal). The variation in  \n");
10787         MrBayesPrint ("                    the Dirichlet can be controlled by this parameter.           \n");
10788         MrBayesPrint ("                    Symdirihyperpr specifies the distribution on the parameter   \n");
10789         MrBayesPrint ("                    of the symmetric Dirichlet. The valid options are:           \n");
10790         MrBayesPrint ("                                                                                 \n");
10791         MrBayesPrint ("                       prset Symdirihyperpr = uniform(<number>,<number>)         \n");
10792         MrBayesPrint ("                       prset Symdirihyperpr = exponential(<number>)              \n");
10793         MrBayesPrint ("                       prset Symdirihyperpr = fixed(<number>)                    \n");
10794         MrBayesPrint ("                       prset Symdirihyperpr = fixed(infinity)                    \n");
10795         MrBayesPrint ("                                                                                 \n");
10796         MrBayesPrint ("                    If \"fixed(infinity)\" is chosen, the Dirichlet prior is     \n");
10797         MrBayesPrint ("                    fixed such that all character states have equal frequency.   \n");
10798         MrBayesPrint ("   Topologypr    -- This parameter specifies the prior probabilities of          \n");
10799         MrBayesPrint ("                    phylogenies. The options are:                                \n");
10800         MrBayesPrint ("                                                                                 \n");
10801         MrBayesPrint ("                       prset topologypr = uniform                                \n");
10802         MrBayesPrint ("                       prset topologypr = speciestree                            \n");
10803         MrBayesPrint ("                       prset topologypr = constraints(<list>)                    \n");
10804         MrBayesPrint ("                       prset topologypr = fixed(<treename>)                      \n");
10805         MrBayesPrint ("                                                                                 \n");
10806         MrBayesPrint ("                    If the prior is selected to be \"uniform\", the default,     \n");
10807         MrBayesPrint ("                    then all possible trees are considered a priori equally      \n");
10808         MrBayesPrint ("                    probable. The 'speciestree' option is used when the topology \n");
10809         MrBayesPrint ("                    is constrained to fold inside a species tree together with   \n");
10810         MrBayesPrint ("                    other (gene) trees. The constraints option allows you to     \n");
10811         MrBayesPrint ("                    specify complicated prior probabilities on trees (constraints\n");
10812         MrBayesPrint ("                    are discussed more fully in \"help constraint\"). Note that  \n");
10813         MrBayesPrint ("                    you must specify a list of constraints that you wish to be   \n");
10814         MrBayesPrint ("                    obeyed. The list can be either the constraints' name or      \n");
10815         MrBayesPrint ("                    number. Finally, you can fix the topology to that of a user  \n");
10816         MrBayesPrint ("                    tree defined in a trees block. Branch lengths will still be  \n");
10817         MrBayesPrint ("                    sampled as usual on the fixed topology.                      \n");
10818         MrBayesPrint ("   Brlenspr      -- This parameter specifies the prior probability dist-         \n");
10819         MrBayesPrint ("                    ribution on branch lengths. The options are specified using: \n");
10820         MrBayesPrint ("                                                                                 \n");
10821         MrBayesPrint ("                       prset brlenspr = <setting>                                \n");
10822         MrBayesPrint ("                                                                                 \n");
10823         MrBayesPrint ("                    where <setting> is one of                                    \n");
10824         MrBayesPrint ("                                                                                 \n");
10825         MrBayesPrint ("                       unconstrained:uniform(<num>,<num>)                        \n");
10826         MrBayesPrint ("                       unconstrained:exponential(<number>)                       \n");
10827         MrBayesPrint ("                       unconstrained:twoexp(<num>,<num>)                         \n");
10828         MrBayesPrint ("                       unconstrained:gammadir(<num>,<num>,<num>,<num>)           \n");
10829         MrBayesPrint ("                       unconstrained:invgamdir(<num>,<num>,<num>,<num>)          \n");
10830         MrBayesPrint ("                       clock:uniform                                             \n");
10831         MrBayesPrint ("                       clock:birthdeath                                          \n");
10832         MrBayesPrint ("                       clock:coalescence                                         \n");
10833         MrBayesPrint ("                       clock:fossilization                                       \n");
10834         MrBayesPrint ("                       clock:speciestree                                         \n");
10835         MrBayesPrint ("                       fixed(<treename>)                                         \n");
10836         MrBayesPrint ("                                                                                 \n");
10837         MrBayesPrint ("                    Trees with unconstrained branch lengths are unrooted         \n");
10838         MrBayesPrint ("                    whereas clock-constrained trees are rooted. The option       \n");
10839         MrBayesPrint ("                    after the colon specifies the details of the probability     \n");
10840         MrBayesPrint ("                    density of branch lengths. If you choose a birth-death       \n");
10841         MrBayesPrint ("                    or coalescence prior, you may want to modify the details     \n");
10842         MrBayesPrint ("                    of the parameters of those processes (speciation rate,       \n");
10843         MrBayesPrint ("                    extinction rate and sample probability for the birth-death   \n");
10844         MrBayesPrint ("                    prior; population size and clock rate parameter for the      \n");
10845         MrBayesPrint ("                    coalescence prior). When gene trees are constrained to fold  \n");
10846         MrBayesPrint ("                    inside species trees, the appropriate branch length prior is \n");
10847         MrBayesPrint ("                    'clock:speciestree'. Under this model, it is possible to     \n");
10848         MrBayesPrint ("                    control whether the population size is constant or variable  \n");
10849         MrBayesPrint ("                    across the species tree using the 'popvarpr' setting.        \n");
10850         MrBayesPrint ("                    Branch lengths can also be fixed but only if the topology is \n");
10851         MrBayesPrint ("                    fixed.                                                       \n");
10852         MrBayesPrint ("                                                                                 \n");
10853         MrBayesPrint ("                    For unconstrained branch lengths, MrBayes offers five alter- \n");
10854         MrBayesPrint ("                    native prior distributions. The first two are the simple     \n");
10855         MrBayesPrint ("                    'uniform' and 'exponential' priors. The 'uniform' prior takes\n");
10856         MrBayesPrint ("                    two parameters, the lower and upper bound of the uniform dis-\n");
10857         MrBayesPrint ("                    tribution, respectively. The 'exponential' prior takes a sin-\n");
10858         MrBayesPrint ("                    gle parameter, the rate of the exponential distribution. The \n");
10859         MrBayesPrint ("                    mean of the exponential distribution is the inverse of the   \n");
10860         MrBayesPrint ("                    rate. For instance, an 'exp(10)' distribution has an expected\n");
10861         MrBayesPrint ("                    mean of 0.1.                                                 \n");
10862         MrBayesPrint ("                    MrBayes also offers three more complex prior distributions   \n");
10863         MrBayesPrint ("                    on unconstrained branch lengths. The two-exponential prior   \n");
10864         MrBayesPrint ("                    (Yang and Rannala 2005; Yang 2007) uses two different expo-  \n"); 
10865         MrBayesPrint ("                    nential distributions, one for internal and one for external \n");
10866         MrBayesPrint ("                    branch lengths. The two-exponential prior is invoked using   \n");
10867         MrBayesPrint ("                    'twoexp(<r_I>,<r_E>)', where '<r_I>' is a number specifying  \n");
10868         MrBayesPrint ("                    the rate of the exponential distribution on internal branch  \n");
10869         MrBayesPrint ("                    lengths, while '<r_E>' is the rate for external branch       \n");
10870         MrBayesPrint ("                    lengths. The prior mean for internal branch lengths is then  \n");
10871         MrBayesPrint ("                    1/r_I, and for external ones is 1/r_E. For instance, to set  \n");
10872         MrBayesPrint ("                    prior mean of internal branch lengths to 0.01, and external  \n");
10873         MrBayesPrint ("                    ones to 0.1, use 'twoexp(100,10)'.                           \n");
10874         MrBayesPrint ("                    The setting 'twoexp(10,10)' is equivalent to 'exp(10)'.      \n");
10875         MrBayesPrint ("                    The compound Dirichlet priors 'gammadir(<a_T>,<b_T>,<a>,<c>)'\n");
10876         MrBayesPrint ("                    and 'invgamdir(<a_T>,<b_T>,<a>,<c>)' specify a fairly diffuse\n");
10877         MrBayesPrint ("                    prior on tree length 'T', and then partition the tree length \n");
10878         MrBayesPrint ("                    into branch lengths according to a Dirichlet distribution    \n");
10879         MrBayesPrint ("                    (Rannala et al. 2012). If 'T' is considered drawn from a     \n");
10880         MrBayesPrint ("                    gamma distribution with parameters a_T and b_T, and with mean\n");
10881         MrBayesPrint ("                    a_T/b_T, we recommend setting a_T = 1; if it is instead con- \n");
10882         MrBayesPrint ("                    sidered drawn from an inverse gamma (invgamma) distribution  \n");
10883         MrBayesPrint ("                    with parameters a_T and b_T, and with mean b_T/(a_T -1), then\n");
10884         MrBayesPrint ("                    we reccommend setting a_T = 3. In the latter case, b_T should\n");
10885         MrBayesPrint ("                    be chosen so that the prior mean of T is reasonable for the  \n");
10886         MrBayesPrint ("                    data. In the former case, setting b_T = 0.1 (corresponding to\n");
10887         MrBayesPrint ("                    a mean tree length of 10) should be appropriate for a wide   \n");
10888         MrBayesPrint ("                    range of tree lengths (at least in the interval 1 to 100).   \n");
10889         MrBayesPrint ("                    The concentration parameter a of the Dirichlet distribution  \n");
10890         MrBayesPrint ("                    is inversely related to the variance of the branch lengths,  \n");
10891         MrBayesPrint ("                    while c is the ratio of the prior means for the internal and \n");
10892         MrBayesPrint ("                    external branch lengths. The default setting, a = c = 1,     \n");
10893         MrBayesPrint ("                    specifies a uniform Dirichlet distribution of branch lengths \n");
10894         MrBayesPrint ("                    given the tree length. For instance, 'gammadir(1,0.1,1,1)'   \n");
10895         MrBayesPrint ("                    specifies a compound Dirichlet prior on branch lengths, where\n");
10896         MrBayesPrint ("                    tree length is associated with a gamma distribution with mean\n");
10897         MrBayesPrint ("                    10, and branch length proportions are associated with a uni- \n");
10898         MrBayesPrint ("                    form Dirichlet distribution (default).                       \n");
10899         MrBayesPrint ("                                                                                 \n");
10900         MrBayesPrint ("                    For clock trees with calibrated external nodes (fossils),    \n");
10901         MrBayesPrint ("                    MrBayes also offers the fossilized birth-death prior:        \n");
10902         MrBayesPrint ("                    'clock:fossilization'.                                       \n");
10903         MrBayesPrint ("                    If 'SampleStrat' is set to 'fossiltip', it assumes that upon \n");
10904         MrBayesPrint ("                    sampling the lineage is dead and won't produce descendants,  \n");
10905         MrBayesPrint ("                    meaning each fossil sample is a tip. If 'SampleStrat' is set \n");
10906         MrBayesPrint ("                    to 'random' (default), fossils are sampled serially along the\n");
10907         MrBayesPrint ("                    birth-death tree (Stadler 2010), so they can be tips or an-  \n");
10908         MrBayesPrint ("                    cestors. See 'Speciationpr', 'Extinctionpr', 'SampleStrat',  \n");
10909         MrBayesPrint ("                    'Fossilizationpr' for more information.                      \n");
10910         MrBayesPrint ("                                                                                 \n");
10911         MrBayesPrint ("   Treeagepr     -- This parameter specifies the prior probability distribution  \n");
10912         MrBayesPrint ("                    on the tree age when a uniform or fossilization prior is used\n");
10913         MrBayesPrint ("                    on the branch lengths of a clock tree.                       \n");
10914         MrBayesPrint ("                                                                                 \n");
10915         MrBayesPrint ("                    The options are:                                             \n");
10916         MrBayesPrint ("                                                                                 \n");
10917         MrBayesPrint ("                       prset treeagepr = <setting>                               \n");
10918         MrBayesPrint ("                                                                                 \n");
10919         MrBayesPrint ("                    where <setting> is one of                                    \n");
10920         MrBayesPrint ("                                                                                 \n");
10921         MrBayesPrint ("                       fixed(<age>)                                              \n");
10922         MrBayesPrint ("                       uniform(<min_age>,<max_age>)                              \n");
10923         MrBayesPrint ("                       offsetexponential(<min_age>,<mean_age>)                   \n");
10924         MrBayesPrint ("                       truncatednormal(<min_age>,<mean_age>,<st.dev.>)           \n");
10925         MrBayesPrint ("                       lognormal(<mean_age>,<st.dev.>)                           \n");
10926         MrBayesPrint ("                       offsetlognormal(<min_age>,<mean_age>,<st.dev.>)           \n");
10927         MrBayesPrint ("                       gamma(<mean_age>,<st.dev.>)                               \n");
10928         MrBayesPrint ("                       offsetgamma(<min_age>,<mean_age>,<st.dev.>)               \n");
10929         MrBayesPrint ("                                                                                 \n");
10930         MrBayesPrint ("                    These are the same options used for the 'Calibrate' command. \n");
10931         MrBayesPrint ("                    Note that, unlike elsewhere in MrMayes, we always use the    \n");
10932         MrBayesPrint ("                    mean and standard deviation of the resulting age distribution\n");
10933         MrBayesPrint ("                    rather than the standard parameterization, if different. This\n");
10934         MrBayesPrint ("                    is to facilitate for the users who want to focus on the in-  \n");
10935         MrBayesPrint ("                    formation conveyed about the age. For those who wish to use  \n");
10936         MrBayesPrint ("                    the standard parameterization, there are simple conversions  \n");
10937         MrBayesPrint ("                    between the two. See the 'Calibrate' command for more infor- \n");
10938         MrBayesPrint ("                    mation.                                                      \n");
10939         MrBayesPrint ("                                                                                 \n");
10940         MrBayesPrint ("                    The tree age is simply the age of the most recent common     \n");
10941         MrBayesPrint ("                    ancestor of the tree. If the clock rate is fixed to 1.0,     \n");
10942         MrBayesPrint ("                    which is the default, the tree age is equivalent to the      \n");
10943         MrBayesPrint ("                    expected number of substitutions from the root to the tip of \n");
10944         MrBayesPrint ("                    the tree, that is, tree height. The tree age prior ensures   \n");
10945         MrBayesPrint ("                    that the joint probability for the uniform prior (or fossil- \n");
10946         MrBayesPrint ("                    ization prior) model of branch lengths on a clock tree is    \n");
10947         MrBayesPrint ("                    proper. The default setting is 'gamma(1,1)'. If the root node\n");
10948         MrBayesPrint ("                    in the tree is calibrated, the root calibration replaces the \n");
10949         MrBayesPrint ("                    tree age prior.                                              \n");
10950         MrBayesPrint ("   Speciationpr  -- This parameter sets the prior on the net speciation rate (net\n");
10951         MrBayesPrint ("                    diversification), that is, (lambda - mu) in the birth-death  \n");
10952         MrBayesPrint ("                    model and the general case of fossilized birth-death model.  \n");
10953         MrBayesPrint ("                    Or, (lambda - mu - psi) in the special case of f-b-d model   \n");
10954         MrBayesPrint ("                    (fossiltip). Values of this parameter are > 0. Prior options:\n");
10955         MrBayesPrint ("                                                                                 \n");
10956         MrBayesPrint ("                       prset speciationpr = uniform(<number>,<number>)           \n");
10957         MrBayesPrint ("                       prset speciationpr = exponential(<number>)                \n");
10958         MrBayesPrint ("                       prset speciationpr = fixed(<number>)                      \n");
10959         MrBayesPrint ("                                                                                 \n");
10960         MrBayesPrint ("                    This parameter is only relevant if the (fossil) birth-death  \n");
10961         MrBayesPrint ("                    process is selected as the prior on branch lengths.          \n");
10962         MrBayesPrint ("   Extinctionpr  -- This parameter sets the prior on the relative extinction rate\n");
10963         MrBayesPrint ("                    (turnover), that is, (mu / lambda) in the birth-death model  \n");
10964         MrBayesPrint ("                    and the general case of fossilized birth-death model.        \n");
10965         MrBayesPrint ("                    Or, (mu + psi) / lambda in the special case of f-b-d model   \n");
10966         MrBayesPrint ("                    (fossiltip). Values of this parameter are in range (0,1).    \n");
10967         MrBayesPrint ("                                                                                 \n");
10968         MrBayesPrint ("                       prset extinctionpr = beta(<number>,<number>)              \n");
10969         MrBayesPrint ("                       prset extinctionpr = fixed(<number>)                      \n");
10970         MrBayesPrint ("                                                                                 \n");
10971         MrBayesPrint ("                    This parameter is only relevant if the (fossil) birth-death  \n");
10972         MrBayesPrint ("                    process is selected as the prior on branch lengths.          \n");
10973         MrBayesPrint (" Fossilizationpr -- This parameter sets the prior on the relative fossilization  \n");
10974         MrBayesPrint ("                    rate (sampling proportion), psi/(mu+psi), in the fossilized  \n");
10975         MrBayesPrint ("                    b-d model. Values of this parameter are in range (0,1).      \n");
10976         MrBayesPrint ("                    If SampleStrat is used to divide up time intervals, it sets  \n");
10977         MrBayesPrint ("                    the prior for the fossilization parameter in each interval.  \n");
10978         MrBayesPrint ("                                                                                 \n");
10979         MrBayesPrint ("                       prset fossilizationpr = beta(<number>,<number>)           \n");
10980         MrBayesPrint ("                       prset fossilizationpr = fixed(<number>)                   \n");
10981         MrBayesPrint ("                                                                                 \n");
10982         MrBayesPrint ("                    This parameter is only relevant if the fossilized birth-death\n");
10983         MrBayesPrint ("                    process is selected as the prior on branch lengths.          \n");
10984         MrBayesPrint ("   SampleStrat   -- This parameter sets the strategy under which species were    \n");
10985         MrBayesPrint ("                    sampled in the analysis. For the birth-death prior, 'birth-  \n");
10986         MrBayesPrint ("                    death' (Hohna et al. 2011), three strategies: 'random',      \n");
10987         MrBayesPrint ("                    'diversity' and 'cluster' sampling can be used for extant    \n");
10988         MrBayesPrint ("                    taxa. No extinct sample (fossil) is allowed in this prior.   \n");
10989         MrBayesPrint ("                    For data with extant and extinct samples, use 'prset brlenspr\n");
10990         MrBayesPrint ("                    =clock:fossilization'. (Stadler 2010; Zhang et al. 2015)     \n");
10991         MrBayesPrint ("                    For the fossilized birth-death prior, 'fossiltip' assumes    \n");
10992         MrBayesPrint ("                    extant taxa are sampled randomly, and extinct taxa (fossils) \n");
10993         MrBayesPrint ("                    are sampled with constant rate and upon sampling the lineage \n");
10994         MrBayesPrint ("                    is dead and won't produce any descendant. So fossils are all \n");
10995         MrBayesPrint ("                    at tips. Except 'fossiltip', the following strategies allow  \n");
10996         MrBayesPrint ("                    fossils also being ancestors of other samples.               \n");
10997         MrBayesPrint ("                    'random' (default) assumes extant taxa are sampled randomly  \n");
10998         MrBayesPrint ("                    with prob rho, while fossils are sampled on the birth-death  \n");
10999         MrBayesPrint ("                    tree with piecewise constant rates, psi_i (i = 1,...,s+1).   \n");
11000         MrBayesPrint ("                    'diversity' assumes extant taxa are sampled to maximize      \n");
11001         MrBayesPrint ("                    diversity, while fossils are sampled randomly.               \n");
11002         MrBayesPrint ("                    Time is divided by <s> slice samping events in the past, each\n");
11003         MrBayesPrint ("                    at time <t_i> with probability <rho_i> (s >= 0). If rho_i = 0\n");
11004         MrBayesPrint ("                    the slice is only used to divide up time intervals not for   \n");
11005         MrBayesPrint ("                    sampling of fossils.  Extant taxa are sampled with prob.     \n");
11006         MrBayesPrint ("                    (proportion) rho (set in sampleprob).                        \n");
11007         MrBayesPrint ("                                                                                 \n");
11008         MrBayesPrint ("                       prset samplestrat = random                                \n");
11009         MrBayesPrint ("                       prset samplestrat = diversity                             \n");
11010         MrBayesPrint ("                       prset samplestrat = cluster                               \n");
11011         MrBayesPrint ("                       prset samplestrat = fossiltip                             \n");
11012         MrBayesPrint ("                       prset samplestrat = random    <s>:...,<t_i> <rho_i>,...   \n");
11013         MrBayesPrint ("                       prset samplestrat = diversity <s>:...,<t_i> <rho_i>,...   \n");
11014         MrBayesPrint ("                                                                                 \n");
11015         MrBayesPrint ("   Sampleprob    -- This parameter sets the fraction of extant species that are  \n");
11016         MrBayesPrint ("                    sampled in the analysis. This is used with the birth-death   \n");
11017         MrBayesPrint ("                    prior on trees (Yang and Rannala 1997; Stadler 2009; Hohna   \n");
11018         MrBayesPrint ("                    et al. 2011), and the fossilized birth-death prior (Stadler  \n");
11019         MrBayesPrint ("                    2010, Zhang et al. 2015).                                    \n");
11020         MrBayesPrint ("                                                                                 \n");
11021         MrBayesPrint ("                       prset sampleprob = <number>                               \n");
11022         MrBayesPrint ("                                                                                 \n");
11023         MrBayesPrint ("   Popsizepr     -- This parameter sets the prior on the population size compo-  \n");
11024         MrBayesPrint ("                    nent of the coalescent parameter. The options are:           \n");
11025         MrBayesPrint ("                                                                                 \n");
11026         MrBayesPrint ("                       prset popsizepr = uniform(<number>,<number>)              \n");
11027         MrBayesPrint ("                       prset popsizepr = lognormal(<number>,<number>)            \n");
11028         MrBayesPrint ("                       prset popsizepr = normal(<number>,<number>)               \n");
11029         MrBayesPrint ("                       prset popsizepr = gamma(<number>,<number>)                \n");
11030         MrBayesPrint ("                       prset popsizepr = fixed(<number>)                         \n");
11031         MrBayesPrint ("                                                                                 \n");
11032         MrBayesPrint ("                    This parameter is only relevant if the coalescence process is\n");
11033         MrBayesPrint ("                    selected as the prior on branch lengths. Note that the set-  \n");
11034         MrBayesPrint ("                    ting of 'ploidy' in 'lset' is important for how this para-   \n");
11035         MrBayesPrint ("                    meter is interpreted.                                        \n");
11036         MrBayesPrint ("   Popvarpr      -- In a gene tree - species tree model, this parameter deter-   \n");
11037         MrBayesPrint ("                    mines whether the population size is the same for the entire \n");
11038         MrBayesPrint ("                    species tree ('popvarpr = equal', the default), or varies    \n");
11039         MrBayesPrint ("                    across branches of the species tree ('popvarpr=variable').   \n");
11040 /*      MrBayesPrint ("   Growthpr      -- This parameter sets the prior on the exponential growth      \n");
11041         MrBayesPrint ("                    parameter of the coalescence process. The options are:       \n");
11042         MrBayesPrint ("                                                                                 \n");
11043         MrBayesPrint ("                       prset growthpr = uniform(<number>,<number>)               \n");
11044         MrBayesPrint ("                       prset growthpr = exponential(<number>)                    \n");
11045         MrBayesPrint ("                       prset growthpr = fixed(<number>)                          \n");
11046         MrBayesPrint ("                                                                                 \n");
11047         MrBayesPrint ("                    This parameter is only relevant if the coalescence           \n");
11048         MrBayesPrint ("                    process is selected as the prior on branch lengths.          \n"); */
11049         MrBayesPrint ("   Nodeagepr     -- This parameter specifies the assumptions concerning the age  \n");
11050         MrBayesPrint ("                    of the terminal and interior nodes in the tree. The default  \n");
11051         MrBayesPrint ("                    model ('nodeagepr = unconstrained') assumes that all terminal\n");
11052         MrBayesPrint ("                    nodes are of the same age while the age of interior nodes is \n");
11053         MrBayesPrint ("                    unconstrained. The alternative ('nodeagepr = calibrated')    \n");
11054         MrBayesPrint ("                    option derives a prior probability distribution on terminal  \n");
11055         MrBayesPrint ("                    and interior node ages from the calibration settings (see    \n");
11056         MrBayesPrint ("                    the 'calibrate' command). The 'nodeagepr' parameter is only  \n");
11057         MrBayesPrint ("                    relevant for clock trees.                                    \n");
11058         MrBayesPrint ("   Clockratepr   -- This parameter specifies the prior assumptions concerning the\n");
11059         MrBayesPrint ("                    base substitution rate of the tree, measured in expected num-\n");
11060         MrBayesPrint ("                    ber of substitutions per site per time unit. The default set-\n");
11061         MrBayesPrint ("                    ting is 'Fixed(1.0)', which effectively means that the time  \n");
11062         MrBayesPrint ("                    unit is the number of expected substitutions per site.       \n");
11063 /*      MrBayesPrint ("                    If you apply age constraints to the tree, the default setting\n");
11064         MrBayesPrint ("                    changes automatically to 'Exponential(<x>)', where '<x>' (the\n");
11065         MrBayesPrint ("                    rate of exponential) is ten times the age of the maximum age \n");
11066         MrBayesPrint ("                    constraint. This will give you a very vague prior, which may \n");
11067         MrBayesPrint ("                    or may not be adequate for your particular problem.          \n"); */
11068         MrBayesPrint ("                    If you do not have any age calibrations in the tree, you can \n");
11069         MrBayesPrint ("                    still calibrate the tree using 'Clockratepr'. For instance,  \n");
11070         MrBayesPrint ("                    if you know that your sequence data evolve at a rate of 0.20 \n");
11071         MrBayesPrint ("                    substitutions per million years, you might calibrate the tree\n");
11072         MrBayesPrint ("                    by fixing the substitution rate to 0.20 using                \n");
11073         MrBayesPrint ("                                                                                 \n");
11074         MrBayesPrint ("                       prset clockratepr = fixed(0.20)                           \n");
11075         MrBayesPrint ("                                                                                 \n");
11076         MrBayesPrint ("                    after which the tree will be calibrated using millions of    \n");
11077         MrBayesPrint ("                    years as the unit.                                           \n");
11078         MrBayesPrint ("                                                                                 \n");
11079         MrBayesPrint ("                    You can also assign a prior probability distribution to the  \n");
11080         MrBayesPrint ("                    substitution rate, accommodating the uncertainty of it.      \n");
11081         MrBayesPrint ("                    When you calibrate the nodes, you should properly set this   \n");
11082         MrBayesPrint ("                    prior to match the time unit of the calibrations.            \n");
11083         MrBayesPrint ("                    You can choose among normal, lognormal, exponential and gamma\n");
11084         MrBayesPrint ("                    distributions for this purpose. For instance, to assign a    \n");
11085         MrBayesPrint ("                    normal distribution truncated at 0, so that only positive    \n");
11086         MrBayesPrint ("                    values are allowed, and with mean 0.20 and standard deviation\n");
11087         MrBayesPrint ("                    of 0.02, you would use                                       \n");
11088         MrBayesPrint ("                                                                                 \n");
11089         MrBayesPrint ("                       prset clockratepr = normal(0.20,0.02)                     \n");
11090         MrBayesPrint ("                                                                                 \n");
11091         MrBayesPrint ("                    The lognormal distribution is parameterized in terms of the  \n");
11092         MrBayesPrint ("                    mean and standard deviation on the log scale (natural logs). \n");
11093         MrBayesPrint ("                    For instance,                                                \n");
11094         MrBayesPrint ("                                                                                 \n");
11095         MrBayesPrint ("                       prset clockratepr = lognormal(-1.61,0.10)                 \n");
11096         MrBayesPrint ("                                                                                 \n");
11097         MrBayesPrint ("                    specifies a lognormal distribution with a mean of log values \n");
11098         MrBayesPrint ("                    of -1.61 and a standard deviation of log values of 0.10. In  \n");
11099         MrBayesPrint ("                    such a case, the mean value of the lognormal distribution is \n");
11100         MrBayesPrint ("                    equal to e^(-1.61 + 0.10^2/2) = 0.20.                        \n");
11101         MrBayesPrint ("                                                                                 \n");
11102         MrBayesPrint ("                    Note that the 'Clockratepr' parameter has no effect on non-  \n");
11103         MrBayesPrint ("                    clock trees.                                                 \n");
11104         MrBayesPrint ("   Clockvarpr    -- This parameter allows you to specify the type of clock you   \n");
11105         MrBayesPrint ("                    are assuming. The default is 'strict', which corresponds to  \n");
11106         MrBayesPrint ("                    the standard clock model where the evolutionary rate is      \n");
11107         MrBayesPrint ("                    constant throughout the tree. For relaxed clock models, you  \n");
11108         MrBayesPrint ("                    can use 'cpp', 'tk02', 'igr'. ('mixed' is not working)       \n");
11109         MrBayesPrint ("                    'cpp' invokes a relaxed clock model where the rate evolves   \n");
11110         MrBayesPrint ("                    according to a Compound Poisson Process (CPP) (Huelsenbeck   \n");
11111         MrBayesPrint ("                    et al., 2000).                                               \n");
11112         MrBayesPrint ("                    'tk02' invokes the Brownian Motion model described by Thorne \n");
11113         MrBayesPrint ("                    and Kishino (2002). [autocorrelated lognormal distributions] \n");
11114         MrBayesPrint ("                    'igr' invokes the Independent Gamma Rate (IGR) model where   \n");
11115         MrBayesPrint ("                    each branch has an independent rate drawn from a gamma       \n");
11116         MrBayesPrint ("                    distribution (LePage et al., 2007).                          \n");
11117         MrBayesPrint ("                    Each of the relaxed clock models has additional parameters   \n");
11118         MrBayesPrint ("                    with priors. For the CPP model, it is 'cppratepr' and        \n");
11119         MrBayesPrint ("                    'cppmultdevpr'; for the TK02 model, it is 'tk02varpr'; for   \n");
11120         MrBayesPrint ("                    the IGR  model, it is 'igrvarpr'.                            \n");
11121         MrBayesPrint ("                    The 'clockvarpr' parameter is only relevant for clock trees. \n");
11122         MrBayesPrint ("                                                                                 \n");
11123         MrBayesPrint ("                    For backward compatibility, 'bm' is allowed as a synonym of  \n");
11124         MrBayesPrint ("                    'tk02', and 'ibr' as a synonym of 'igr'.                     \n");
11125         MrBayesPrint ("   Cppratepr     -- This parameter allows you to specify a prior probability     \n");
11126         MrBayesPrint ("                    distribution on the rate of the Poisson process generating   \n");
11127         MrBayesPrint ("                    changes in the evolutionary rate in the CPP relaxed clock    \n");
11128         MrBayesPrint ("                    model. You can either fix the rate or associate it with an   \n");
11129         MrBayesPrint ("                    exponential prior using                                      \n");
11130         MrBayesPrint ("                                                                                 \n");
11131         MrBayesPrint ("                       prset cppratepr = fixed(<number>)                         \n");
11132         MrBayesPrint ("                       prset cppratepr = exponential(<number>)                   \n");
11133         MrBayesPrint ("                                                                                 \n");
11134         MrBayesPrint ("                    For instance, if you fix the rate to 2, then on a branch     \n");
11135         MrBayesPrint ("                    with the length equual to one expresed in terms of average   \n");
11136         MrBayesPrint ("                    expected number of substitution per site, you expect to see, \n"); 
11137         MrBayesPrint ("                    on average, two rate-modifying events.                       \n");
11138         MrBayesPrint ("                    If you put an exponential(0.1) on the rate, you will be      \n");
11139         MrBayesPrint ("                    estimating the rate against a prior probability distribution \n");
11140         MrBayesPrint ("                    where the expected rate is 10 (= 1/0.1).                     \n");
11141         MrBayesPrint ("   Cppmultdevpr  -- This parameter allows you to specify the standard deviation  \n");
11142         MrBayesPrint ("                    of the log-normal distribution from which the rate multi-    \n");
11143         MrBayesPrint ("                    pliers of the CPP relaxed clock model are drawn. The standard\n");
11144         MrBayesPrint ("                    deviation is given on the log scale. The default value of 1.0\n");
11145         MrBayesPrint ("                    thus corresponds to rate multipliers varying from 0.37 (1/e) \n");
11146         MrBayesPrint ("                    to 2.7 (e) when they are +/- one standard deviation from the \n");
11147         MrBayesPrint ("                    expected mean. The expected mean of the logarithm of the mul-\n");
11148         MrBayesPrint ("                    pliers is fixed to 0, ensuring that the expected mean rate is\n");
11149         MrBayesPrint ("                    1.0. You can change the default value by using               \n");
11150         MrBayesPrint ("                                                                                 \n");
11151         MrBayesPrint ("                       prset cppmultdevpr = fixed(<number>)                      \n");
11152         MrBayesPrint ("                                                                                 \n");
11153         MrBayesPrint ("                    where <number> is the standard deviation on the log scale.   \n");
11154         MrBayesPrint ("   TK02varpr     -- This parameter allows you to specify the prior probability   \n");
11155         MrBayesPrint ("                    distribution for the variance of the rate multiplier in the  \n");
11156         MrBayesPrint ("                    Thorne-Kishino ('Brownian motion') relaxed clock model.      \n");
11157         MrBayesPrint ("                    Specifically, the parameter specifies the rate at which the  \n");
11158         MrBayesPrint ("                    variance increases with respect to the base rate of the      \n");
11159         MrBayesPrint ("                    clock. If you have a branch of a length corresponding to 0.4 \n");
11160         MrBayesPrint ("                    expected changes per site according to the base rate of the  \n");
11161         MrBayesPrint ("                    clock, and the tk02var parameter has a value of 2.0, then the\n");
11162         MrBayesPrint ("                    rate multiplier at the end of the branch will be drawn from a\n");
11163         MrBayesPrint ("                    lognormal distribution with a variance of 0.4*2.0 (on the    \n");
11164         MrBayesPrint ("                    linear, not the logarithm scale). The mean is the same as the\n");
11165         MrBayesPrint ("                    rate multiplier at the start of the branch (again on the     \n");
11166         MrBayesPrint ("                    linear scale).                                               \n");
11167         MrBayesPrint ("                                                                                 \n");
11168         MrBayesPrint ("                    You can set the parameter to a fixed value, or specify that  \n");
11169         MrBayesPrint ("                    it is drawn from an exponential or uniform distribution:     \n");
11170         MrBayesPrint ("                                                                                 \n");
11171         MrBayesPrint ("                       prset tk02varpr = fixed(<number>)                         \n");
11172         MrBayesPrint ("                       prset tk02varpr = exponential(<number>)                   \n");
11173         MrBayesPrint ("                       prset tk02varpr = uniform(<number>,<number>)              \n");
11174         MrBayesPrint ("                                                                                 \n");
11175         MrBayesPrint ("                    For backward compatibility, 'bmvarpr' is allowed as a synonym\n");
11176         MrBayesPrint ("                    of 'tko2varpr'.                                              \n");
11177         MrBayesPrint ("   Igrvarpr      -- This parameter allows you to specify a prior on the variance \n");
11178         MrBayesPrint ("                    of the gamma distribution from which the branch lengths are  \n");
11179         MrBayesPrint ("                    drawn in the independent branch rate (IGR) relaxed clock     \n");
11180         MrBayesPrint ("                    model. Specifically, the parameter specifies the rate at     \n");
11181         MrBayesPrint ("                    which the variance increases with respect to the base rate of\n");
11182         MrBayesPrint ("                    the clock. If you have a branch of a length corresponding to \n");
11183         MrBayesPrint ("                    0.4 expected changes per site according to the base rate of  \n");
11184         MrBayesPrint ("                    the clock, and the igrvar parameter has a value of 2.0, then \n");
11185         MrBayesPrint ("                    the effective branch length will be drawn from a distribution\n");
11186         MrBayesPrint ("                    with a variance of 0.4*2.0.                                  \n");
11187         MrBayesPrint ("                                                                                 \n");
11188         MrBayesPrint ("                    You can set the parameter to a fixed value, or specify that  \n");
11189         MrBayesPrint ("                    it is drawn from an exponential or uniform distribution:     \n");
11190         MrBayesPrint ("                                                                                 \n");
11191         MrBayesPrint ("                       prset igrvarpr = fixed(<number>)                          \n");
11192         MrBayesPrint ("                       prset igrvarpr = exponential(<number>)                    \n");
11193         MrBayesPrint ("                       prset igrvarpr = uniform(<number>,<number>)               \n");
11194         MrBayesPrint ("                                                                                 \n");
11195         MrBayesPrint ("                    For backward compatibility, 'ibrvarpr' is allowed as a syn-  \n");
11196         MrBayesPrint ("                    onym of 'igrvarpr'.                                          \n");
11197         MrBayesPrint ("   Ratepr        -- This parameter allows you to specify the site specific rates \n");
11198         MrBayesPrint ("                    model or any other model that allows different partitions to \n");
11199         MrBayesPrint ("                    evolve at different rates. First, you must have defined a    \n");
11200         MrBayesPrint ("                    partition of the characters. For example, you may define a   \n");
11201         MrBayesPrint ("                    partition that divides the characters by codon position, if  \n");
11202         MrBayesPrint ("                    you have DNA data. You can also divide your data using a     \n");
11203         MrBayesPrint ("                    partition that separates different genes from each other.    \n");
11204         MrBayesPrint ("                    The next step is to make the desired partition the active one\n");
11205         MrBayesPrint ("                    using the set command. For example, if your partition is     \n");
11206         MrBayesPrint ("                    called \"by_codon\", then you make that the active partition \n");
11207         MrBayesPrint ("                    using \"set partition=by_codon\". Now that you have defined  \n");
11208         MrBayesPrint ("                    and activated a partition, you can specify the rate multi-   \n");
11209         MrBayesPrint ("                    pliers for the various partitions. The options are:          \n");
11210         MrBayesPrint ("                                                                                 \n");
11211         MrBayesPrint ("                       prset ratepr = fixed                                      \n");
11212         MrBayesPrint ("                       prset ratepr = variable                                   \n");
11213         MrBayesPrint ("                       prset ratepr = dirichlet(<number>,<number>,...,<number>)  \n");
11214         MrBayesPrint ("                                                                                 \n");
11215         MrBayesPrint ("                    If you specify \"fixed\", then the rate multiplier for       \n");
11216         MrBayesPrint ("                    that partition is set to 1 (i.e., the rate is fixed to       \n");
11217         MrBayesPrint ("                    the average rate across partitions). On the other hand,      \n");
11218         MrBayesPrint ("                    if you specify \"variable\", then the rate is allowed to     \n");
11219         MrBayesPrint ("                    vary across partitions subject to the constraint that the    \n");
11220         MrBayesPrint ("                    average rate of substitution across the partitions is 1.     \n");
11221         MrBayesPrint ("                    You must specify a variable rate prior for at least two      \n");
11222         MrBayesPrint ("                    partitions, otherwise the option is not activated when       \n");
11223         MrBayesPrint ("                    calculating likelihoods. The variable option automatically   \n");
11224         MrBayesPrint ("                    associates the partition rates with a dirichlet(1,...,1)     \n");
11225         MrBayesPrint ("                    prior. The dirichlet option is an alternative way of setting \n");
11226         MrBayesPrint ("                    a partition rate to be variable, and also gives accurate     \n");
11227         MrBayesPrint ("                    control of the shape of the prior. The parameters of the     \n");
11228         MrBayesPrint ("                    Dirichlet are listed in the order of the partitions that the \n");
11229         MrBayesPrint ("                    ratepr is applied to. For instance, \"prset applyto=(1,3,4)  \n");
11230         MrBayesPrint ("                    ratepr = dirichlet(10,40,15)\" would set the Dirichlet para- \n");
11231         MrBayesPrint ("                    meter 10 to partition 1, 40 to partition 3, and 15 to parti- \n");
11232         MrBayesPrint ("                    tion 4. The Dirichlet distribution is applied to the weighted\n");
11233         MrBayesPrint ("                    rates; that is, it weights the partition rates according to  \n");
11234         MrBayesPrint ("                    the number of included characters in each partition.         \n");
11235         MrBayesPrint ("   Generatepr    -- This parameter is similar to 'Ratepr' but applies to gene    \n");
11236         MrBayesPrint ("                    trees in the multispecies coalescent, whereas 'Ratepr' app-  \n");
11237         MrBayesPrint ("                    lies to partitions within genes.                             \n");
11238         MrBayesPrint ("                                                                                 \n");
11239         if (numCurrentDivisions == 0)
11240             tempInt = 1;
11241         else
11242             tempInt = numCurrentDivisions;
11243         for (i=0; i<tempInt; i++)
11244             {
11245             if (numCurrentDivisions == 0)
11246                 {
11247                 MrBayesPrint ("   Default model settings:                                                       \n");
11248                 mp = &defaultModel;
11249                 }
11250             else
11251                 {
11252                 MrBayesPrint ("   Model settings for partition %d:                                              \n", i+1);
11253                 mp = &modelParams[i];
11254                 }
11255             MrBayesPrint ("                                                                                 \n");
11256             MrBayesPrint ("   Parameter        Options                      Current Setting                 \n");
11257             MrBayesPrint ("   ------------------------------------------------------------------            \n");
11258
11259             MrBayesPrint ("   Tratiopr         Beta/Fixed                   %s", mp->tRatioPr);
11260             if (!strcmp(mp->tRatioPr, "Beta"))
11261                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->tRatioDir[0], mp->tRatioDir[1]);
11262             else
11263                 MrBayesPrint ("(%1.1lf)\n", mp->tRatioFix);
11264
11265             MrBayesPrint ("   Revmatpr         Dirichlet/Fixed              %s", mp->revMatPr);
11266             if (!strcmp(mp->revMatPr, "Dirichlet"))
11267                 MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf,%1.1lf,%1.1lf,%1.1lf)\n", mp->revMatDir[0],
11268                 mp->revMatDir[1], mp->revMatDir[2], mp->revMatDir[3],
11269                 mp->revMatDir[4], mp->revMatDir[5]);
11270             else
11271                 MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf,%1.1lf,%1.1lf,%1.1lf)\n", mp->revMatFix[0],
11272                 mp->revMatFix[1], mp->revMatFix[2], mp->revMatFix[3],
11273                 mp->revMatFix[4], mp->revMatFix[5]);
11274
11275             MrBayesPrint ("   Aamodelpr        Fixed/Mixed                  %s", mp->aaModelPr);
11276             if (!strcmp(mp->aaModelPr, "Fixed"))
11277                 MrBayesPrint ("(%s)\n", mp->aaModel);
11278             else
11279                 MrBayesPrint ("\n");
11280
11281             MrBayesPrint ("   Aarevmatpr       Dirichlet/Fixed              %s", mp->aaRevMatPr);
11282             if (!strcmp(mp->aaRevMatPr, "Dirichlet"))
11283                 {
11284                 for (j=1; j<190; j++)
11285                     if (AreDoublesEqual (mp->aaRevMatDir[0], mp->aaRevMatDir[j], 0.00001) == NO)
11286                         break;
11287                 if (j==190)
11288                     MrBayesPrint ("(%1.1lf,%1.1lf,...)\n", mp->aaRevMatDir[0], mp->aaRevMatDir[0]);
11289                 else
11290                     MrBayesPrint (" (use 'Showmodel' to see values set by user)\n");
11291                 }
11292             else
11293                 {
11294                 for (j=1; j<190; j++)
11295                     if (AreDoublesEqual (mp->aaRevMatFix[0], mp->aaRevMatFix[j], 0.00001) == NO)
11296                         break;
11297                 if (j==190)
11298                     MrBayesPrint ("(%1.1lf,%1.1lf,...)\n", mp->aaRevMatFix[0], mp->aaRevMatFix[0]);
11299                 else
11300                     MrBayesPrint (" (use 'Showmodel' to see values set by user)\n");
11301                 }
11302
11303             MrBayesPrint ("   Omegapr          Dirichlet/Fixed              %s", mp->omegaPr);
11304             if (!strcmp(mp->omegaPr, "Dirichlet"))
11305                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->omegaDir[0], mp->omegaDir[1]);
11306             else
11307                 MrBayesPrint ("(%1.1lf)\n", mp->omegaFix);
11308
11309             MrBayesPrint ("   Ny98omega1pr     Beta/Fixed                   %s", mp->ny98omega1pr);
11310             if (!strcmp(mp->ny98omega1pr, "Beta"))
11311                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->ny98omega1Beta[0], mp->ny98omega1Beta[1]);
11312             else if (!strcmp(mp->ny98omega1pr, "Fixed"))
11313                 MrBayesPrint ("(%1.1lf)\n", mp->ny98omega1Fixed);
11314                 
11315             MrBayesPrint ("   Ny98omega3pr     Uniform/Exponential/Fixed    %s", mp->ny98omega3pr);
11316             if (!strcmp(mp->ny98omega3pr, "Uniform"))
11317                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->ny98omega3Uni[0], mp->ny98omega3Uni[1]);
11318             else if (!strcmp(mp->ny98omega3pr, "Exponential"))
11319                 MrBayesPrint ("(%1.1lf)\n", mp->ny98omega3Exp);
11320             else
11321                 MrBayesPrint ("(%1.1lf)\n", mp->ny98omega3Fixed);
11322
11323             MrBayesPrint ("   M3omegapr        Exponential/Fixed            %s", mp->m3omegapr);
11324             if (!strcmp(mp->m3omegapr, "Exponential"))
11325                 MrBayesPrint ("\n");
11326             else if (!strcmp(mp->m3omegapr, "Fixed"))
11327                 MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf)\n", mp->m3omegaFixed[0], mp->m3omegaFixed[1], mp->m3omegaFixed[2]);
11328                 
11329             MrBayesPrint ("   Codoncatfreqs    Dirichlet/Fixed              %s", mp->codonCatFreqPr);
11330             if (!strcmp(mp->codonCatFreqPr, "Dirichlet"))
11331                 MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf)\n", mp->codonCatDir[0], mp->codonCatDir[1], mp->codonCatDir[2]);
11332             else
11333                 MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf)\n", mp->codonCatFreqFix[0], mp->codonCatFreqFix[1], mp->codonCatFreqFix[2]);
11334
11335             MrBayesPrint ("   Statefreqpr      Dirichlet/Fixed              %s", mp->stateFreqPr);
11336             if (!strcmp(mp->stateFreqPr, "Dirichlet"))
11337                 {
11338                 if (mp->dataType == DNA || mp->dataType == RNA)
11339                     {
11340                     if (!strcmp(mp->nucModel, "4by4"))
11341                         MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf,%1.1lf)\n", mp->stateFreqsDir[0], mp->stateFreqsDir[1],
11342                             mp->stateFreqsDir[2], mp->stateFreqsDir[3]);
11343                     else
11344                         MrBayesPrint ("\n");
11345                     }
11346                 else if (mp->dataType == RESTRICTION)
11347                     {
11348                     MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->stateFreqsDir[0], mp->stateFreqsDir[1]);
11349                     }
11350                 else
11351                     MrBayesPrint ("\n");
11352                 }
11353             else if (!strcmp(mp->stateFreqPr, "Fixed"))
11354                 {
11355                 if (mp->dataType == DNA || mp->dataType == RNA)
11356                     {
11357                     if (!strcmp(mp->nucModel, "4by4"))
11358                         MrBayesPrint ("(%1.1lf,%1.1lf,%1.1lf,%1.1lf)\n", mp->stateFreqsFix[0], mp->stateFreqsFix[1],
11359                             mp->stateFreqsFix[2], mp->stateFreqsFix[3]);
11360                     else
11361                         MrBayesPrint ("\n");
11362                     }
11363                 else if (mp->dataType == RESTRICTION)
11364                     {
11365                     MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->stateFreqsFix[0], mp->stateFreqsFix[1]);
11366                     }
11367                 else
11368                     MrBayesPrint ("\n");
11369                 }
11370
11371             MrBayesPrint ("   Shapepr          Uniform/Exponential/Fixed    %s", mp->shapePr);
11372             if (!strcmp(mp->shapePr, "Uniform"))
11373                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->shapeUni[0], mp->shapeUni[1]);
11374             else if (!strcmp(mp->shapePr, "Exponential"))
11375                 MrBayesPrint ("(%1.1lf)\n", mp->shapeExp);
11376             else
11377                 MrBayesPrint ("(%1.1lf)\n", mp->shapeFix);
11378
11379             MrBayesPrint ("   Ratecorrpr       Uniform/Fixed                %s", mp->adGammaCorPr);
11380             if (!strcmp(mp->adGammaCorPr, "Uniform"))
11381                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->corrUni[0], mp->corrUni[1]);
11382             else
11383                 MrBayesPrint ("(%1.1lf)\n", mp->corrFix);
11384
11385             MrBayesPrint ("   Pinvarpr         Uniform/Fixed                %s", mp->pInvarPr);
11386             if (!strcmp(mp->pInvarPr, "Uniform"))
11387                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->pInvarUni[0], mp->pInvarUni[1]);
11388             else
11389                 MrBayesPrint ("(%1.1lf)\n", mp->pInvarFix);
11390
11391             MrBayesPrint ("   Covswitchpr      Uniform/Exponential/Fixed    %s", mp->covSwitchPr);
11392             if (!strcmp(mp->covSwitchPr, "Uniform"))
11393                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->covswitchUni[0], mp->covswitchUni[1]);
11394             else if (!strcmp(mp->covSwitchPr, "Exponential"))
11395                 MrBayesPrint ("(%1.1lf)\n", mp->covswitchExp);
11396             else
11397                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->covswitchFix[0], mp->covswitchFix[1]);
11398
11399             MrBayesPrint ("   Symdirihyperpr   Uniform/Exponential/Fixed    %s", mp->symPiPr);
11400             if (!strcmp(mp->symPiPr, "Uniform"))
11401                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->symBetaUni[0], mp->symBetaUni[1]);
11402             else if (!strcmp(mp->covSwitchPr, "Exponential"))
11403                 MrBayesPrint ("(%1.1lf)\n", mp->symBetaExp);
11404             else
11405                 {
11406                 if (mp->symBetaFix < 0)
11407                     MrBayesPrint ("(Infinity)\n");
11408                 else
11409                     MrBayesPrint ("(%1.1lf)\n", mp->symBetaFix);
11410                 }
11411             
11412             MrBayesPrint ("   Topologypr       Uniform/Constraints/Fixed/   %s", mp->topologyPr);
11413             if (!strcmp(mp->topologyPr, "Constraints"))
11414                 {
11415                 MrBayesPrint ("(");
11416                 for (j=0; j<numDefinedConstraints; j++)
11417                     {
11418                     if (mp->activeConstraints[j] == YES)
11419                         {
11420                         MrBayesPrint ("%d", j+1);
11421                         break;
11422                         }
11423                     }
11424                for (j++; j<numDefinedConstraints; j++)
11425                     {
11426                     if (mp->activeConstraints[j] == YES)
11427                         {
11428                         MrBayesPrint (",%d", j+1);
11429                         }
11430                     }
11431                 MrBayesPrint (")\n");
11432                 }
11433             else if (!strcmp(mp->topologyPr, "Fixed"))
11434                 MrBayesPrint("(%s)\n", userTree[mp->topologyFix]->name);
11435             else
11436                 MrBayesPrint ("\n");
11437             MrBayesPrint ("                    Speciestree                  \n");
11438             
11439             MrBayesPrint ("   Brlenspr         Unconstrained/Clock/Fixed    %s", mp->brlensPr);
11440             if (!strcmp(mp->brlensPr, "Unconstrained"))
11441                 {
11442                 if (!strcmp(mp->unconstrainedPr, "Uniform"))
11443                     MrBayesPrint (":Uni(%1.1lf,%1.1lf)\n", mp->brlensUni[0], mp->brlensUni[1]);
11444                 else if (!strcmp(mp->unconstrainedPr, "GammaDir"))
11445                     MrBayesPrint (":GammaDir(%1.1lf,%1.3lf,%1.1lf,%1.1lf)\n",
11446                                 mp->brlensDir[0], mp->brlensDir[1], mp->brlensDir[2], mp->brlensDir[3]);
11447                 else if (!strcmp(mp->unconstrainedPr, "invGamDir"))
11448                     MrBayesPrint (":invGamDir(%1.1lf,%1.3lf,%1.1lf,%1.1lf)\n",
11449                                 mp->brlensDir[0], mp->brlensDir[1], mp->brlensDir[2], mp->brlensDir[3]);
11450                 else if (!strcmp(mp->unconstrainedPr, "twoExp"))
11451                     MrBayesPrint (":twoExp(%1.1lf,%1.1lf)\n", mp->brlens2Exp[0], mp->brlens2Exp[1]);
11452                 else
11453                     MrBayesPrint (":Exp(%1.1lf)\n", mp->brlensExp);
11454                 }
11455             else if (!strcmp(mp->brlensPr, "Clock"))
11456                 {
11457                 if (!strcmp(mp->clockPr,"Fixed"))
11458                     MrBayesPrint (":%s(%s)\n", mp->clockPr, userTree[mp->brlensFix]->name);
11459                 else
11460                     MrBayesPrint (":%s\n", mp->clockPr);
11461                 }
11462             else if (!strcmp(mp->brlensPr, "Fixed"))
11463                 MrBayesPrint("(%s)\n", userTree[mp->brlensFix]->name);
11464             
11465             MrBayesPrint ("   Treeagepr        Gamma/Uniform/Fixed/         %s\n", mp->treeAgePr.name);
11466             MrBayesPrint ("                    Truncatednormal/Lognormal/   \n");
11467             MrBayesPrint ("                    Offsetlognormal/Offsetgamma/ \n");
11468             MrBayesPrint ("                    Offsetexponential            \n");
11469             
11470             MrBayesPrint ("   Speciationpr     Uniform/Exponential/Fixed    %s", mp->speciationPr);
11471             if (!strcmp(mp->speciationPr, "Uniform"))
11472                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->speciationUni[0], mp->speciationUni[1]);
11473             else if (!strcmp(mp->speciationPr, "Exponential"))
11474                 MrBayesPrint ("(%1.1lf)\n", mp->speciationExp);
11475             else
11476                 MrBayesPrint ("(%1.1lf)\n", mp->speciationFix);
11477             
11478             MrBayesPrint ("   Extinctionpr     Beta/Fixed                   %s", mp->extinctionPr);
11479             if (!strcmp(mp->extinctionPr, "Beta"))
11480                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->extinctionBeta[0], mp->extinctionBeta[1]);
11481             else
11482                 MrBayesPrint ("(%1.1lf)\n", mp->extinctionFix);
11483             
11484             MrBayesPrint ("   Fossilizationpr  Beta/Fixed                   %s", mp->fossilizationPr);
11485             if (!strcmp(mp->fossilizationPr, "Beta"))
11486                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->fossilizationBeta[0], mp->fossilizationBeta[1]);
11487             else
11488                 MrBayesPrint ("(%1.2lf)\n", mp->fossilizationFix);
11489             
11490             MrBayesPrint ("   SampleStrat      Random/Diversity/Cluster/    %s\n", mp->sampleStrat);
11491             MrBayesPrint ("                    FossilTip                    \n");
11492             // if (!strcmp(mp->sampleStrat, "Random") || !strcmp(mp->sampleStrat, "Diversity"))
11493             
11494             MrBayesPrint ("   Sampleprob       <number>                     %1.8lf\n", mp->sampleProb);
11495             
11496             MrBayesPrint ("   Popsizepr        Lognormal/Gamma/Uniform/     %s", mp->popSizePr);
11497             if (!strcmp(mp->popSizePr, "Uniform"))
11498                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->popSizeUni[0], mp->popSizeUni[1]);
11499             else if (!strcmp(mp->popSizePr, "Lognormal"))
11500                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->popSizeLognormal[0], mp->popSizeLognormal[1]);
11501             else if (!strcmp(mp->popSizePr, "Normal"))
11502                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->popSizeNormal[0], mp->popSizeNormal[1]);
11503             else if (!strcmp(mp->popSizePr, "Gamma"))
11504                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->popSizeGamma[0], mp->popSizeGamma[1]);
11505             else
11506                 MrBayesPrint ("(%1.1lf)\n", mp->popSizeFix);
11507             MrBayesPrint ("                    Normal/Fixed                 \n");
11508
11509             MrBayesPrint ("   Popvarpr         Equal/Variable               %s\n", mp->popVarPr);
11510
11511             /*
11512             MrBayesPrint ("   Growthpr         Uniform/Exponential/         \n");
11513             MrBayesPrint ("                    Fixed/Normal                 %s", mp->growthPr);
11514             if (!strcmp(mp->growthPr, "Uniform"))
11515                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->growthUni[0], mp->growthUni[1]);
11516             else if (!strcmp(mp->growthPr, "Exponential"))
11517                 MrBayesPrint ("(%1.1lf)\n", mp->growthExp);
11518             else if (!strcmp(mp->growthPr, "Normal"))
11519                 MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->growthNorm[0], mp->growthNorm[1]);
11520             else
11521                 MrBayesPrint ("(%1.1lf)\n", mp->growthFix); 
11522             */
11523
11524             MrBayesPrint ("   Nodeagepr        Unconstrained/Calibrated     %s\n", mp->nodeAgePr);
11525
11526             MrBayesPrint ("   Clockratepr      Fixed/Normal/Lognormal/      %s", mp->clockRatePr);
11527             if (!strcmp(mp->clockRatePr, "Fixed"))
11528                 MrBayesPrint ("(%1.2lf)\n", mp->clockRateFix);
11529             else if (!strcmp(mp->clockRatePr,"Exponential"))
11530                 MrBayesPrint ("(%1.2lf)\n", mp->clockRateExp);
11531             else if (!strcmp(mp->clockRatePr,"Normal"))
11532                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->clockRateNormal[0], mp->clockRateNormal[1]);
11533             else if (!strcmp(mp->clockRatePr,"Lognormal"))
11534                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->clockRateLognormal[0], mp->clockRateLognormal[1]);
11535             else
11536                 {
11537                 assert (!strcmp(mp->clockRatePr,"Gamma"));
11538                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->clockRateGamma[0], mp->clockRateGamma[1]);
11539                 }
11540             MrBayesPrint ("                    Exponential/Gamma            \n");
11541
11542             MrBayesPrint ("   Clockvarpr       Strict/Cpp/TK02/Igr/Mixed    %s\n", mp->clockVarPr);
11543
11544             MrBayesPrint ("   Cppratepr        Fixed/Exponential            %s", mp->cppRatePr);
11545             if (!strcmp(mp->cppRatePr, "Fixed"))
11546                 MrBayesPrint ("(%1.2lf)\n", mp->cppRateFix);
11547             else /* if (!strcmp(mp->cppRatePr,"Exponential")) */
11548                 MrBayesPrint ("(%1.2lf)\n", mp->cppRateExp);
11549
11550             MrBayesPrint ("   Cppmultdevpr     Fixed                        %s", mp->cppMultDevPr);
11551             MrBayesPrint ("(%1.2lf)\n", mp->cppMultDevFix);
11552
11553             MrBayesPrint ("   TK02varpr        Fixed/Exponential/Uniform    %s", mp->tk02varPr);
11554             if (!strcmp(mp->tk02varPr, "Fixed"))
11555                 MrBayesPrint ("(%1.2lf)\n", mp->tk02varFix);
11556             else if (!strcmp(mp->tk02varPr,"Exponential"))
11557                 MrBayesPrint ("(%1.2lf)\n", mp->tk02varExp);
11558             else
11559                 {
11560                 assert (!strcmp(mp->tk02varPr,"Uniform"));
11561                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->tk02varUni[0], mp->tk02varUni[1]);
11562                 }
11563
11564             MrBayesPrint ("   Igrvarpr         Fixed/Exponential/Uniform    %s", mp->igrvarPr);
11565             if (!strcmp(mp->igrvarPr, "Fixed"))
11566                 MrBayesPrint ("(%1.2lf)\n", mp->igrvarFix);
11567             else if (!strcmp(mp->igrvarPr,"Exponential"))
11568                 MrBayesPrint ("(%1.2lf)\n", mp->igrvarExp);
11569             else
11570                 {
11571                 assert (!strcmp(mp->igrvarPr,"Uniform"));
11572                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->igrvarUni[0], mp->igrvarUni[1]);
11573                 }
11574             
11575             /*  MrBayesPrint ("   Mixedvarpr       Fixed/Exponential/Uniform    %s", mp->mixedvarPr);
11576             if (!strcmp(mp->mixedvarPr, "Fixed"))
11577                 MrBayesPrint ("(%1.2lf)\n", mp->mixedvarFix);
11578             else if (!strcmp(mp->mixedvarPr,"Exponential"))
11579                 MrBayesPrint ("(%1.2lf)\n", mp->mixedvarExp);
11580             else
11581                 {
11582                 assert (!strcmp(mp->mixedvarPr,"Uniform"));
11583                 MrBayesPrint ("(%1.2lf,%1.2lf)\n", mp->mixedvarUni[0], mp->mixedvarUni[1]);
11584                 }  */
11585
11586             MrBayesPrint ("   Ratepr           Fixed/Variable=Dirichlet     %s", mp->ratePr);
11587             if (!strcmp(mp->ratePr, "Dirichlet"))
11588                 MrBayesPrint ("(...,%1.1lf,...)\n", mp->ratePrDir);
11589             else
11590                 MrBayesPrint ("\n");
11591
11592             MrBayesPrint ("   Generatepr       Fixed/Variable=Dirichlet     %s", mp->generatePr);
11593             if (!strcmp(mp->generatePr, "Dirichlet"))
11594                 MrBayesPrint ("(...,%1.1lf,...)\n", mp->generatePrDir);
11595             else
11596                 MrBayesPrint ("\n");
11597
11598             MrBayesPrint ("   ------------------------------------------------------------------            \n");
11599             MrBayesPrint ("                                                                                 \n");
11600             }
11601         }
11602     else if (!strcmp(helpTkn, "Ctype"))
11603         {
11604         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11605         MrBayesPrint ("   Ctype                                                                         \n");
11606         MrBayesPrint ("                                                                                 \n");
11607         MrBayesPrint ("   This command sets the character ordering for standard-type data. The          \n");
11608         MrBayesPrint ("   correct usage is:                                                             \n");
11609         MrBayesPrint ("                                                                                 \n");
11610         MrBayesPrint ("      ctype <ordering>:<characters>                                              \n");
11611         MrBayesPrint ("                                                                                 \n");
11612         MrBayesPrint ("   The available options for the <ordering> specifier are:                       \n");
11613         MrBayesPrint ("                                                                                 \n");
11614         MrBayesPrint ("     unordered    -- Movement directly from one state to another is              \n");
11615         MrBayesPrint ("                     allowed in an instant of time.                              \n");
11616         MrBayesPrint ("     ordered      -- Movement is only allowed between adjacent characters.       \n");
11617         MrBayesPrint ("                     For example, perhaps only between 0 <-> 1 and 1 <-> 2       \n");
11618         MrBayesPrint ("                     for a three state character ordered as 0 - 1 - 2.           \n");
11619         MrBayesPrint ("     irreversible -- Rates of change for losses are 0.                           \n");
11620         MrBayesPrint ("                                                                                 \n");
11621         MrBayesPrint ("   The characters to which the ordering is applied is specified in manner        \n");
11622         MrBayesPrint ("   that is identical to commands such as \"include\" or \"exclude\". For         \n");
11623         MrBayesPrint ("   example,                                                                      \n");
11624         MrBayesPrint ("                                                                                 \n");
11625         MrBayesPrint ("      ctype ordered: 10 23 45                                                    \n");
11626         MrBayesPrint ("                                                                                 \n");
11627         MrBayesPrint ("   defines charactes 10, 23, and 45 to be of type ordered. Similarly,            \n");
11628         MrBayesPrint ("                                                                                 \n");
11629         MrBayesPrint ("      ctype irreversible: 54 - 67  71-92                                         \n");
11630         MrBayesPrint ("                                                                                 \n");
11631         MrBayesPrint ("   defines characters 54 to 67 and characters 71 to 92 to be of type             \n");
11632         MrBayesPrint ("   irreversible. You can use the \".\" to denote the last character, and         \n");
11633         MrBayesPrint ("   \"all\" to denote all of the characters. Finally, you can use the             \n");
11634         MrBayesPrint ("   specifier \"\\\" to apply the ordering to every n-th character or             \n");
11635         MrBayesPrint ("   you can use predefined charsets to specify the character.                     \n");
11636         MrBayesPrint ("                                                                                 \n");
11637         MrBayesPrint ("   Only one ordering can be used on any specific application of ctype.           \n");
11638         MrBayesPrint ("   If you want to apply different orderings to different characters, then        \n");
11639         MrBayesPrint ("   you need to use ctype multiple times. For example,                            \n");
11640         MrBayesPrint ("                                                                                 \n");
11641         MrBayesPrint ("      ctype ordered: 1-50                                                        \n");
11642         MrBayesPrint ("      ctype irreversible: 51-100                                                 \n");
11643         MrBayesPrint ("                                                                                 \n");
11644         MrBayesPrint ("   sets characters 1 to 50 to be ordered and characters 51 to 100 to be          \n");
11645         MrBayesPrint ("   irreversible.                                                                 \n");
11646         MrBayesPrint ("                                                                                 \n");
11647         MrBayesPrint ("   The ctype command is only sensible with morphological (here called            \n");
11648         MrBayesPrint ("   \"standard\") characters. The program ignores attempts to apply char-         \n");
11649         MrBayesPrint ("   acter orderings to other types of characters, such as DNA characters.         \n");
11650
11651         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11652         }
11653     else if (!strcmp(helpTkn, "Propset"))
11654         {
11655         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11656         MrBayesPrint ("   Propset                                                                       \n");
11657         MrBayesPrint ("                                                                                 \n");
11658         MrBayesPrint ("   This command allows the user to change the details of the MCMC samplers       \n");
11659         MrBayesPrint ("   (moves) that update the state of the chain. The useage is:                    \n");
11660         MrBayesPrint ("                                                                                 \n");
11661         MrBayesPrint ("      propset  <move_name>$<tuning-parameter>=<value>                            \n");
11662         MrBayesPrint ("                                                                                 \n");
11663         MrBayesPrint ("   Assume we have a topology parameter called 'Tau{all}', which is sampled by    \n");
11664         MrBayesPrint ("   the move 'ExtTBR(Tau{all})' (note that the parameter name is included in the  \n");
11665         MrBayesPrint ("   move name). This move has three tuning parameters: (1) 'prob', the relative   \n");
11666         MrBayesPrint ("   proposal probability (a weight defining its probability relative to other     \n");
11667         MrBayesPrint ("   moves); (2) 'p_ext', the extension probability; and (3) 'lambda', the tuning  \n");
11668         MrBayesPrint ("   parameter of the branch length multiplier. A list of the tuning parameters is \n");
11669         MrBayesPrint ("   available by using 'Showmoves' (see below). To change the relative proposal   \n");
11670         MrBayesPrint ("   probability to 20 and the extension probability to 0.7, use:                  \n");
11671         MrBayesPrint ("                                                                                 \n");
11672         MrBayesPrint ("      propset etbr(tau{all})$prob=20 etbr(tau{all})$p_ext=0.7                    \n");
11673         MrBayesPrint ("                                                                                 \n");
11674         MrBayesPrint ("   This change would apply to all chains in all runs. It is also possible to set \n");
11675         MrBayesPrint ("   the tuning parameters of individual runs and chains using the format:         \n");
11676         MrBayesPrint ("                                                                                 \n");
11677         MrBayesPrint ("      propset  <move_name>$<tuning-parameter>(<run>,<chain>)=<value>             \n");
11678         MrBayesPrint ("                                                                                 \n");
11679         MrBayesPrint ("   where <run> and <chain> are the index numbers of the run and chain for which  \n");
11680         MrBayesPrint ("   you want to change the value. If you leave out the index of the run, the      \n");
11681         MrBayesPrint ("   change will apply to all runs; if you leave out the index of the chain, the   \n");
11682         MrBayesPrint ("   change will similarly apply to all chains. To switch off the exttbr(tau{all}) \n");
11683         MrBayesPrint ("   move in chain 2 of all runs, use:                                             \n");
11684         MrBayesPrint ("                                                                                 \n");
11685         MrBayesPrint ("      propset  etbr(tau{all})$prob(,2)=0                                         \n");
11686         MrBayesPrint ("                                                                                 \n");
11687         MrBayesPrint ("   It is important to note that all moves are not available until the model has  \n");
11688         MrBayesPrint ("   been completely defined. Any change to the model will cause all proposal      \n");
11689         MrBayesPrint ("   tuning parameters to return to their default values. To see a list of all the \n");
11690         MrBayesPrint ("   moves that are currently switched on for the model, use 'showmoves'. You can  \n");
11691         MrBayesPrint ("   also see other available moves by using 'showmoves allavailable=yes'. A list  \n");
11692         MrBayesPrint ("   of the moves for each parameter in the model is available by using the command\n");
11693         MrBayesPrint ("   'Showparams'. If you change proposal probabilities, make sure that all        \n");
11694         MrBayesPrint ("   parameters that are not fixed in your model have at least one move switched   \n");
11695         MrBayesPrint ("   on.                                                                           \n");
11696         MrBayesPrint ("                                                                                 \n");
11697         MrBayesPrint ("   One word of warning: You should be extremely careful when modifying any       \n");
11698         MrBayesPrint ("   of the chain parameters using 'propset'. It is quite possible to completely   \n");
11699         MrBayesPrint ("   wreck any hope of achieving convergence by inappropriately setting the        \n");
11700         MrBayesPrint ("   tuning parameters. In general, you want to set move tuning parameters such    \n");
11701         MrBayesPrint ("   that the acceptance rate of the move is intermediate (we suggest targeting    \n");
11702         MrBayesPrint ("   the range 10%% to 70%% acceptance, if possible). If the acceptance rate is    \n");
11703         MrBayesPrint ("   outside of this range, the MCMC chain will probably not sample that parameter \n");
11704         MrBayesPrint ("   very efficiently. The acceptance rates for all moves in the cold chain(s) are \n");
11705         MrBayesPrint ("   summarized at the end of each run in the screen output. The acceptance rates  \n");
11706         MrBayesPrint ("   (potentially for all chains, cold and heated) are also printed to the .mcmc   \n");
11707         MrBayesPrint ("   file if Mcmc convergence diagnostics are turned on (using 'Mcmc' or 'Mcmcp'). \n");
11708         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11709         }
11710     else if (!strcmp(helpTkn, "Log"))
11711         {
11712         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11713         MrBayesPrint ("   Log                                                                           \n");
11714         MrBayesPrint ("                                                                                 \n");
11715         MrBayesPrint ("   This command allows output to the screen to also be output to a file.         \n");
11716         MrBayesPrint ("   The useage is:                                                                \n");
11717         MrBayesPrint ("                                                                                 \n");
11718         MrBayesPrint ("      log start/stop filename=<name> append/replace                              \n");
11719         MrBayesPrint ("                                                                                 \n");
11720         MrBayesPrint ("   The options are:                                                              \n");
11721         MrBayesPrint ("                                                                                 \n");
11722         MrBayesPrint ("   Start/Stop     -- Starts or stops logging of output to file.                  \n");
11723         MrBayesPrint ("   Append/Replace -- Either append to or replace existing file.                  \n");
11724         MrBayesPrint ("   Filename       -- Name of log file (currently, the name of the log            \n");
11725         MrBayesPrint ("                     file is \"%s\").\n", logFileName);
11726         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11727         }
11728     else if (!strcmp(helpTkn, "Translate"))
11729         {
11730         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11731         MrBayesPrint ("   Translate                                                                     \n");
11732         MrBayesPrint ("                                                                                 \n");
11733         MrBayesPrint ("   This command is used by MrBayes to specify the mapping between taxon names    \n");
11734         MrBayesPrint ("   and taxon numbers in a Nexus tree file. For instance,                         \n");
11735         MrBayesPrint ("                                                                                 \n");
11736         MrBayesPrint ("      translate                                                                  \n");
11737         MrBayesPrint ("         1 Homo,                                                                 \n");
11738         MrBayesPrint ("         2 Pan,                                                                  \n");
11739         MrBayesPrint ("         3 Gorilla,                                                              \n");
11740         MrBayesPrint ("         4 Hylobates;                                                            \n");
11741         MrBayesPrint ("                                                                                 \n");
11742         MrBayesPrint ("   establishes that the taxon labeled 1 in the trees that follow is Homo, the    \n");
11743         MrBayesPrint ("   taxon labeled 2 is Pan, etc.                                                  \n");
11744         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11745         }
11746     else if (!strcmp(helpTkn, "Usertree"))
11747         {
11748         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11749         MrBayesPrint ("   Usertree                                                                      \n");
11750         MrBayesPrint ("                                                                                 \n");
11751         MrBayesPrint ("   This command allows you to specify a user tree. The user tree can then be     \n");
11752         MrBayesPrint ("   used as a starting tree for a MCMC analysis. The format for the command is    \n");
11753         MrBayesPrint ("                                                                                 \n");
11754         MrBayesPrint ("      usertree = <tree in Newick format>                                         \n");
11755         MrBayesPrint ("                                                                                 \n");
11756         MrBayesPrint ("   For example,                                                                  \n");
11757         MrBayesPrint ("                                                                                 \n");
11758         MrBayesPrint ("      usertree = (A,B,(C,D))                                                     \n");
11759         MrBayesPrint ("                                                                                 \n");
11760         MrBayesPrint ("   specifies an unrooted tree of four species. Note that the program re-         \n");
11761         MrBayesPrint ("   quires that trees are binary (i.e., strictly bifurcating). Hence, there       \n");
11762         MrBayesPrint ("   can be only one three-way split, as shown in the example. If the tree         \n");
11763         MrBayesPrint ("   is not binary, the program will return an error.                              \n");
11764         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11765         }
11766     else if (!strcmp(helpTkn, "Mcmc"))
11767         {
11768         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11769         MrBayesPrint ("   Mcmc                                                                          \n");
11770         MrBayesPrint ("                                                                                 \n");
11771         MrBayesPrint ("   This command starts the Markov chain Monte Carlo (MCMC) analysis. The         \n");
11772         MrBayesPrint ("   posterior probability of phylogenetic trees (and other parameters of the      \n");
11773         MrBayesPrint ("   substitution model) cannot be determined analytically. Instead, MCMC is       \n");
11774         MrBayesPrint ("   used to approximate the posterior probabilities of trees by drawing           \n");
11775         MrBayesPrint ("   (dependent) samples from the posterior distribution. This program can         \n");
11776         MrBayesPrint ("   implement a variant of MCMC called \"Metropolis-coupled Markov chain Monte    \n");
11777         MrBayesPrint ("   Carlo\", or MCMCMC for short. Basically, \"Nchains\" are run, with            \n");
11778         MrBayesPrint ("   Nchains - 1 of them heated. The chains are labelled 1, 2, ..., Nchains.       \n");
11779         MrBayesPrint ("   The heat that is applied to the i-th chain is B = 1 / (1 + temp X i). B       \n");
11780         MrBayesPrint ("   is the power to which the posterior probability is raised. When B = 0, all    \n");
11781         MrBayesPrint ("   trees have equal probability and the chain freely visits trees. B = 1 is      \n");
11782         MrBayesPrint ("   the \"cold\" chain (or the distribution of interest). MCMCMC can mix          \n");
11783         MrBayesPrint ("   better than ordinary MCMC; after all of the chains have gone through          \n");
11784         MrBayesPrint ("   one cycle, two chains are chosen at random and an attempt is made to          \n");
11785         MrBayesPrint ("   swap the states (with the probability of a swap being determined by the       \n");
11786         MrBayesPrint ("   Metropolis et al. equation). This allows the chain to potentially jump        \n");
11787         MrBayesPrint ("   a valley in a single bound. The correct usage is                              \n");
11788         MrBayesPrint ("                                                                                 \n");
11789         MrBayesPrint ("      mcmc <parameter> = <value> ... <parameter> = <value>                       \n");
11790         MrBayesPrint ("                                                                                 \n");
11791         MrBayesPrint ("   For example,                                                                  \n");
11792         MrBayesPrint ("                                                                                 \n");
11793         MrBayesPrint ("      mcmc ngen=100000 nchains=4 temp=0.5                                        \n");
11794         MrBayesPrint ("                                                                                 \n");
11795         MrBayesPrint ("   performs a MCMCMC analysis with four chains with the temperature set to       \n");
11796         MrBayesPrint ("   0.5. The chains would be run for 100,000 cycles.                              \n");
11797         MrBayesPrint ("                                                                                 \n");
11798         MrBayesPrint ("   Options:                                                                      \n");
11799         MrBayesPrint ("                                                                                 \n");
11800         MrBayesPrint ("   Ngen         -- This option sets the number of cycles for the MCMC alg-       \n");
11801         MrBayesPrint ("                   orithm. This should be a big number as you want the chain     \n");
11802         MrBayesPrint ("                   to first reach stationarity, and then remain there for        \n");
11803         MrBayesPrint ("                   enough time to take lots of samples.                          \n");
11804         MrBayesPrint ("   Nruns        -- How many independent analyses are started simultaneously.     \n");
11805         MrBayesPrint ("   Nchains      -- How many chains are run for each analysis for the MCMCMC      \n");
11806         MrBayesPrint ("                   variant. The default is 4: 1 cold chain and 3 heated chains.  \n");
11807         MrBayesPrint ("                   If Nchains is set to 1, MrBayes will use regular MCMC sam-    \n");
11808         MrBayesPrint ("                   pling, without heating.                                       \n");
11809         MrBayesPrint ("   Temp         -- The temperature parameter for heating the chains. The higher  \n");
11810         MrBayesPrint ("                   the temperature, the more likely the heated chains are to     \n");
11811         MrBayesPrint ("                   move between isolated peaks in the posterior distribution.    \n");
11812         MrBayesPrint ("                   However, excessive heating may lead to very low acceptance    \n");
11813         MrBayesPrint ("                   rates for swaps between different chains. Before changing the \n");
11814         MrBayesPrint ("                   default setting, however, note that the acceptance rates of   \n");
11815         MrBayesPrint ("                   swaps tend to fluctuate during the burn-in phase of the run.  \n");
11816         MrBayesPrint ("   Reweight     -- Here, you specify three numbers, that respectively represent  \n");
11817         MrBayesPrint ("                   the percentage of characters to decrease in weight, the       \n");
11818         MrBayesPrint ("                   percentage of characters to increase in weight, and the       \n");
11819         MrBayesPrint ("                   increment. An increase/decrease in weight is acheived by      \n");
11820         MrBayesPrint ("                   replicating/removing a character in the matrix. This is       \n");
11821         MrBayesPrint ("                   only done to non-cold chains. The format for this parameter   \n");
11822         MrBayesPrint ("                   is \"reweight=(<number>,<number>)\" or \"reweight=(<number>,  \n");
11823         MrBayesPrint ("                   <number>,<number>)\".                                         \n");
11824         MrBayesPrint ("   Swapfreq     -- This specifies how often swaps of states between chains are   \n");
11825         MrBayesPrint ("                   attempted. You must be running at least two chains for this   \n");
11826         MrBayesPrint ("                   option to be relevant. The default is Swapfreq=1, resulting   \n");
11827         MrBayesPrint ("                   in Nswaps (see below) swaps being tried each generation of    \n");
11828         MrBayesPrint ("                   the run. If Swapfreq is set to 10, then Nswaps swaps will be  \n");
11829         MrBayesPrint ("                   tried every tenth generation of the run.                      \n");
11830         MrBayesPrint ("   Nswaps       -- The number of swaps tried for each swapping generation of the \n");
11831         MrBayesPrint ("                   chain (see also Swapfreq).                                    \n");
11832         MrBayesPrint ("   Samplefreq   -- This specifies how often the Markov chain is sampled. You     \n");
11833         MrBayesPrint ("                   can sample the chain every cycle, but this results in very    \n");
11834         MrBayesPrint ("                   large output files. Thinning the chain is a way of making     \n");
11835         MrBayesPrint ("                   these files smaller and making the samples more independent.  \n");
11836         MrBayesPrint ("   Printfreq    -- This specifies how often information about the chain is       \n");
11837         MrBayesPrint ("                   printed to the screen.                                        \n");
11838         MrBayesPrint ("   Printall     -- If set to NO, only cold chains in a MCMC analysis are printed \n");
11839         MrBayesPrint ("                   to screen. If set to YES, both cold and heated chains will be \n");
11840         MrBayesPrint ("                   output. This setting only affects the printing to screen, it  \n");
11841         MrBayesPrint ("                   does not change the way values are written to file.           \n");
11842         MrBayesPrint ("   Printmax     -- The maximum number of chains to print to screen.              \n");
11843         MrBayesPrint ("   Mcmcdiagn    -- Determines whether acceptance ratios of moves and swaps will  \n");
11844         MrBayesPrint ("                   be printed to file. The file will be named similarly to the   \n");
11845         MrBayesPrint ("                   '.p' and '.t' files, but will have the ending '.mcmc'. If     \n");
11846         MrBayesPrint ("                   more than one independent analysis is run simultaneously (see \n");
11847         MrBayesPrint ("                   Nruns below), convergence diagnostics for tree topology will  \n");
11848         MrBayesPrint ("                   also be printed to this file. The convergence diagnostic used \n");
11849         MrBayesPrint ("                   is the average standard deviation in partition frequency      \n");
11850         MrBayesPrint ("                   values across independent analyses. The Burnin setting (see   \n");
11851         MrBayesPrint ("                   below) determines how many samples will be discarded as burnin\n");
11852         MrBayesPrint ("                   before calculating the partition frequencies. The Minpartfreq \n");
11853         MrBayesPrint ("                   setting (see below) determines the minimum partition frequency\n");
11854         MrBayesPrint ("                   required for a partition to be included in the calculation. As\n");
11855         MrBayesPrint ("                   the independent analyses approach stationarity (converge), the\n");
11856         MrBayesPrint ("                   value of the diagnostic is expected to approach zero.         \n");
11857         MrBayesPrint ("   Diagnfreq    -- The number of generations between the calculation of MCMC     \n");
11858         MrBayesPrint ("                   diagnostics (see Mcmcdiagn above).                            \n");
11859         MrBayesPrint ("   Diagnstat    -- The statistic to use for run-time convergence diagnostics.    \n");
11860         MrBayesPrint ("                   Choices are 'Avgstddev' for average standard deviation of     \n");
11861         MrBayesPrint ("                   split frequencies and 'Maxstddev' for maximum standard devia- \n");
11862         MrBayesPrint ("                   tion of split frequencies.                                    \n");
11863         MrBayesPrint ("   Savetrees    -- If you are using a relative burnin for run-time convergence   \n");
11864         MrBayesPrint ("                   diagnostics, tree samples need to be deleted from split       \n");
11865         MrBayesPrint ("                   frequency counters as the cut-off point for the burnin moves  \n");
11866         MrBayesPrint ("                   during the run. If 'Savetrees' is set to 'No', tree samples   \n");
11867         MrBayesPrint ("                   to be discarded are read back in from file. If 'Savetrees' is \n");
11868         MrBayesPrint ("                   set to 'Yes', the tree samples to be removed will be stored   \n");
11869         MrBayesPrint ("                   in the internal memory instead. This can use up a lot of      \n");
11870         MrBayesPrint ("                   memory in large analyses.                                     \n");
11871         MrBayesPrint ("   Minpartfreq  -- The minimum frequency required for a partition to be included \n");
11872         MrBayesPrint ("                   in the calculation of the topology convergence diagnostic. The\n");
11873         MrBayesPrint ("                   partition is included if the minimum frequency is reached in  \n");
11874         MrBayesPrint ("                   at least one of the independent tree samples that are com-    \n");
11875         MrBayesPrint ("                   pared.                                                        \n");
11876         MrBayesPrint ("   Allchains    -- If this option is set to YES, acceptance ratios for moves are \n");
11877         MrBayesPrint ("                   recorded for all chains, cold or heated. By default, only the \n");
11878         MrBayesPrint ("                   acceptance ratios for the cold chain are recorded.            \n");
11879         MrBayesPrint ("   Allcomps     -- If this option is set to YES, topological convergence diag-   \n");
11880         MrBayesPrint ("                   nostics are calculated over all pairwise comparisons of runs. \n");
11881         MrBayesPrint ("                   If it is set to NO, only the overall value is reported.       \n");
11882         MrBayesPrint ("   Relburnin    -- If this option is set to YES, then a proportion of the sampled\n");
11883         MrBayesPrint ("                   values will be discarded as burnin when calculating the con-  \n");
11884         MrBayesPrint ("                   vergence diagnostic. The proportion to be discarded is set    \n");
11885         MrBayesPrint ("                   with Burninfrac (see below). When the Relburnin option is set \n");
11886         MrBayesPrint ("                   to NO, then a specific number of samples will be discarded    \n");
11887         MrBayesPrint ("                   instead. This number is set by Burnin (see below).            \n");
11888         MrBayesPrint ("   Burnin       -- Determines the number of samples (not generations) that will  \n");
11889         MrBayesPrint ("                   be discarded when convergence diagnostics are calculated.     \n");
11890         MrBayesPrint ("                   The value of this option is only relevant when Relburnin is   \n");
11891         MrBayesPrint ("                   set to NO.                                                    \n");
11892         MrBayesPrint ("   BurninFrac   -- Determines the fraction of samples that will be discarded     \n");
11893         MrBayesPrint ("                   when convergence diagnostics are calculated. The value of     \n");
11894         MrBayesPrint ("                   this option is only relevant when Relburnin is set to YES.    \n");
11895         MrBayesPrint ("                   Example: A value for this option of 0.25 means that 25%% of   \n");
11896         MrBayesPrint ("                   the samples will be discarded.                                \n");
11897         MrBayesPrint ("   Stoprule     -- If this option is set to NO, then the chain is run the number \n");
11898         MrBayesPrint ("                   of generations determined by Ngen. If it is set to YES, and   \n");
11899         MrBayesPrint ("                   topological convergence diagnostics are calculated (Mcmcdiagn \n");
11900         MrBayesPrint ("                   is set to YES), then the chain will be stopped before the pre-\n");
11901         MrBayesPrint ("                   determined number of generations if the convergence diagnostic\n");
11902         MrBayesPrint ("                   falls below the stop value.                                   \n");
11903         MrBayesPrint ("   Stopval      -- The critical value for the topological convergence diagnostic.\n");
11904         MrBayesPrint ("                   Only used when Stoprule and Mcmcdiagn are set to yes, and     \n");
11905         MrBayesPrint ("                   more than one analysis is run simultaneously (Nruns > 1).     \n");
11906         MrBayesPrint ("   Checkpoint   -- If this parameter is set to 'Yes', all the current parameter  \n");
11907         MrBayesPrint ("                   values of all chains will be printed to a check-pointing file \n");
11908         MrBayesPrint ("                   every 'Checkfreq' generation of the analysis. The file will be\n");
11909         MrBayesPrint ("                   named <Filename>.ckp and allows you to restart the analysis   \n");
11910         MrBayesPrint ("                   from the last check point. This can be handy if you are       \n");
11911         MrBayesPrint ("                   running a long analysis and want to extend it, or if there is \n");
11912         MrBayesPrint ("                   a risk that a long analysis will be inadvertently interupted  \n");
11913         MrBayesPrint ("                   by hardware failure or other factors that are out of your     \n");
11914         MrBayesPrint ("                   control.                                                      \n");
11915         MrBayesPrint ("   Checkfreq    -- The number of generations between check-pointing. See the     \n");
11916         MrBayesPrint ("                   'Checkpoint' parameter above for more information.            \n");
11917         MrBayesPrint ("   Filename     -- The name of the files that will be generated. Two files       \n");
11918         MrBayesPrint ("                   are generated: \"<Filename>.t\" and \"<Filename>.p\".         \n");
11919         MrBayesPrint ("                   The .t file contains the trees whereas the .p file con-       \n");
11920         MrBayesPrint ("                   tains the sampled values of the parameters.                   \n");
11921         MrBayesPrint ("   Startparams  -- The starting values for the model parameters are set to       \n");
11922         MrBayesPrint ("                   arbitrary or random values when the parameters are created.   \n");
11923         MrBayesPrint ("                   These starting values can be altered using the 'Startvals'    \n");
11924         MrBayesPrint ("                   command. The 'Startparams=reset' option allows you to reset   \n");
11925         MrBayesPrint ("                   the starting values to the default at the start of the ana-   \n");
11926         MrBayesPrint ("                   lysis, overriding any previous user-defined starting values.  \n");
11927         MrBayesPrint ("                   Under the default option, 'current', the chains will use the  \n");
11928         MrBayesPrint ("                   current starting values.                                      \n");
11929         MrBayesPrint ("   Starttree    -- The starting tree(s) for the chain can either be randomly     \n");
11930         MrBayesPrint ("                   selected or user-defined. It might be a good idea to          \n");
11931         MrBayesPrint ("                   start from randomly chosen trees; convergence seems           \n");
11932         MrBayesPrint ("                   likely if independently run chains, each of which             \n");
11933         MrBayesPrint ("                   started from different random trees, converge to the same     \n");
11934         MrBayesPrint ("                   answer. If you want the chain to start from user-defined      \n");
11935         MrBayesPrint ("                   trees instead, you first need to read in your tree(s) from a  \n");
11936         MrBayesPrint ("                   Nexus file with a 'trees' block, and then you need to set the \n");
11937         MrBayesPrint ("                   starting tree(s) using the 'Startvals' command. Finally, you  \n");
11938         MrBayesPrint ("                   need to make sure that 'Starttree' is set to 'current'. If    \n");
11939         MrBayesPrint ("                   you do not set the starting tree(s), the chains will start    \n");
11940         MrBayesPrint ("                   with random trees. Setting 'Starttree' to 'random' causes     \n");
11941         MrBayesPrint ("                   new starting trees to be drawn randomly at the start of the   \n");
11942         MrBayesPrint ("                   run, overwriting any previous user-defined starting trees.    \n");
11943         MrBayesPrint ("   Nperts       -- This is the number of random perturbations to apply to the    \n");
11944         MrBayesPrint ("                   user starting tree. This allows you to have something         \n");
11945         MrBayesPrint ("                   between completely random and user-defined trees start        \n");
11946         MrBayesPrint ("                   the chain.                                                    \n");
11947 /*      MrBayesPrint ("   Savebrlens   -- This specifies whether branch length information is           \n");
11948         MrBayesPrint ("                   saved on the trees.                                           \n"); */
11949         MrBayesPrint ("   Data         -- When Data is set to NO, the chain is run without data. This   \n");
11950         MrBayesPrint ("                   should be used only for examining induced priors. DO NOT SET  \n");
11951         MrBayesPrint ("                   'DATA' TO 'NO' UNLESS YOU KNOW WHAT YOU ARE DOING!            \n");
11952         MrBayesPrint ("   Ordertaxa    -- Determines whether taxa should be ordered before trees are    \n");
11953         MrBayesPrint ("                   printed to file. If set to 'Yes', terminals in the sampled    \n");
11954         MrBayesPrint ("                   trees will be reordered to match the order of the taxa in the \n");
11955         MrBayesPrint ("                   data matrix as closely as possible. By default, trees will be \n");
11956         MrBayesPrint ("                   printed without reordering of taxa.                           \n");
11957         MrBayesPrint ("   Append       -- Set this to 'Yes' to append the results of the current run to \n");
11958         MrBayesPrint ("                   a previous run. MrBayes will first read in the results of the \n");
11959         MrBayesPrint ("                   previous run (number of generations and sampled splits) and   \n");
11960         MrBayesPrint ("                   will then continue that run where you left it off. Make sure  \n");
11961         MrBayesPrint ("                   that the output file names used in the previous run are the   \n");
11962         MrBayesPrint ("                   same as those in the current run.                             \n");
11963         MrBayesPrint ("   Autotune     -- Set this to 'Yes' to autotune the proposals that change       \n");
11964         MrBayesPrint ("                   substitution model parameters. When set to 'No', the tuning   \n");
11965         MrBayesPrint ("                   parameters are fixed to their starting values. Note that the  \n");
11966         MrBayesPrint ("                   autotuning occurs independently for each chain. The target    \n");
11967         MrBayesPrint ("                   acceptance rate for each move can be changed using the        \n");
11968         MrBayesPrint ("                   'Propset' command.                                            \n");
11969         MrBayesPrint ("   Tunefreq     -- When a proposal has been tried 'Tunefreq' times, its tuning   \n");
11970         MrBayesPrint ("                   parameter is adjusted to reach the target acceptance rate     \n");
11971         MrBayesPrint ("                   if 'Autotune' is set to 'Yes'.                                \n");
11972         MrBayesPrint ("                                                                                 \n");
11973         PrintSettings ("Mcmc");
11974         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11975         }
11976     else if (!strcmp(helpTkn, "Mcmcp"))
11977         {
11978         // PrintYesNo (chainParams.saveBrlens, yesNoStr);
11979         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11980         MrBayesPrint ("   Mcmcp                                                                         \n");
11981         MrBayesPrint ("                                                                                 \n");
11982         MrBayesPrint ("   This command sets the parameters of the Markov chain Monte Carlo (MCMC)       \n");
11983         MrBayesPrint ("   analysis without actually starting the chain. This command is identical       \n");
11984         MrBayesPrint ("   in all respects to Mcmc, except that the analysis will not start after        \n");
11985         MrBayesPrint ("   this command is issued. For more details on the options, check the help       \n");
11986         MrBayesPrint ("   menu for Mcmc.\n");
11987         MrBayesPrint ("                                                                                 \n");
11988         PrintSettings ("Mcmc");
11989         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11990         }
11991     else if (!strcmp(helpTkn, "Ss"))
11992         {
11993         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
11994         MrBayesPrint ("   Ss                                                                            \n");
11995         MrBayesPrint ("                                                                                 \n");
11996         MrBayesPrint ("   This command is used to start stepping-stone sampling, which is an efficient  \n");
11997         MrBayesPrint ("   and accurate method for estimating the marginal likelihood of the currently   \n");
11998         MrBayesPrint ("   specified model. It is considerably more accurate than the harmonic mean of   \n");
11999         MrBayesPrint ("   the likelihoods from a standard MCMC run on the model (calculated by the      \n");
12000         MrBayesPrint ("   'Sump' command) but it requires a separate MCMC-like run. To be more specific,\n");
12001         MrBayesPrint ("   stepping-stone sampling uses importance sampling to estimate each ratio in a  \n");
12002         MrBayesPrint ("   series of discrete steps bridging the posterior and prior distributions.      \n");
12003         MrBayesPrint ("   The importance distributions that are used are called power posterior distri- \n");
12004         MrBayesPrint ("   butions, and are defined as prior*(likelihood^beta). By varying beta from 1 to\n");
12005         MrBayesPrint ("   0, we get a series of distributions that connect the posterior (beta = 1) to  \n");
12006         MrBayesPrint ("   the prior (beta = 0).                                                         \n");
12007         MrBayesPrint ("                                                                                 \n");
12008         MrBayesPrint ("   The power posterior distributions are sampled using MCMC. First, we start a   \n");
12009         MrBayesPrint ("   standard MCMC chain on the posterior distribution, and let it run until we    \n");
12010         MrBayesPrint ("   have reached the criterion specified by the 'Burninss' option. After this, we \n");
12011         MrBayesPrint ("   step through the power posterior distributions until we reach the prior dis-  \n");
12012         MrBayesPrint ("   tribution. In each of the 'Nsteps' steps, we sample from a new power poster-  \n");
12013         MrBayesPrint ("   ior distribution with a distinct beta value. The beta values correspond to    \n");
12014         MrBayesPrint ("   'Nsteps' evenly spaced quantiles in a Beta distribution with the parameters   \n");
12015         MrBayesPrint ("   'Alpha' and 1.0. For the first sampling step, the beta value is equal to the  \n");
12016         MrBayesPrint ("   last quantile, i.e., it is close to 1.0. For each successive step, the beta   \n");
12017         MrBayesPrint ("   value takes on the value of the next quantile, in decreasing order, until it  \n");
12018         MrBayesPrint ("   reaches the value of 0.0. If you change value of 'FromPrior' from default 'No'\n");
12019         MrBayesPrint ("   to 'Yes' then the direction of power posterior change during SS analizes is   \n");
12020         MrBayesPrint ("   opposite to the one described above, i.e. we start from sampling prior and    \n");
12021         MrBayesPrint ("   finish close to posterior.                                                    \n");
12022         MrBayesPrint ("                                                                                 \n");
12023         MrBayesPrint ("   The 'Ss' procedure uses the same machinery as the standard 'Mcmc' algorithm,  \n");
12024         MrBayesPrint ("   and shares most of its parameters with the 'Mcmc' and 'Mcmcp' commands. All   \n");
12025         MrBayesPrint ("   'Mcmc' parameters, except those related to burnin, have the same meaning and  \n");
12026         MrBayesPrint ("   usage in the 'Ss' command as they have in the 'Mcmc' command. The 'Mcmc'      \n");
12027         MrBayesPrint ("   burnin parameters are used to set up burnin within each step. The 'Ss' command\n");
12028         MrBayesPrint ("   also uses its own burnin parameter, 'Burninss' (see below for details). The   \n");
12029         MrBayesPrint ("   'Ss' command also has its own parameters for specifying the number of steps   \n");
12030         MrBayesPrint ("   and the shape of the Beta distribution from which the beta values are computed\n");
12031         MrBayesPrint ("   (see below).                                                                  \n");
12032         MrBayesPrint ("                                                                                 \n");
12033         MrBayesPrint ("   Note that the 'Ngen' parameter of 'Mcmc' is used to set the maximum number of \n");
12034         MrBayesPrint ("   generations processed, including both the burnin and the following steps in   \n");
12035         MrBayesPrint ("   the stepping-stone sampling phase. For instance, assume that 'Burninss' is set\n");
12036         MrBayesPrint ("   to '-1', 'Nsteps' to '49', 'Ngen' to '1000000' and 'Samplefreq' to '1000'.    \n");
12037         MrBayesPrint ("   We will then get 1,000 samples in total (1,000,000 / 1,000). These will fall  \n");
12038         MrBayesPrint ("   into 50 bins, one of which represents the burnin and is discarded. Each step  \n");
12039         MrBayesPrint ("   in the algorithm will thus be represented by 20 samples.                      \n");
12040         MrBayesPrint ("                                                                                 \n");
12041         MrBayesPrint ("   More information on 'Mcmc' parameters is available in the help for the 'Mcmc' \n");
12042         MrBayesPrint ("   and 'Mcmcp' commands. Only the exclusive 'Ss' parameters are listed below.    \n");
12043         MrBayesPrint ("   These can only be set up using the 'Ss' command, while the parameters shared  \n");
12044         MrBayesPrint ("   with 'Mcmc' and 'Mcmcp' can also be set up using those commands.              \n");
12045         MrBayesPrint ("                                                                                 \n");
12046         MrBayesPrint ("   The correct usage is                                                          \n");
12047         MrBayesPrint ("                                                                                 \n");
12048         MrBayesPrint ("      ss <parameter>=<value> ... <parameter>=<value>                             \n");
12049         MrBayesPrint ("                                                                                 \n");
12050         MrBayesPrint ("   Note that a command:                                                          \n");
12051         MrBayesPrint ("                                                                                 \n");
12052         MrBayesPrint ("      ss <setting parameters shared with mcmc> <setting exclusive ss parameters> \n");
12053         MrBayesPrint ("                                                                                 \n");
12054         MrBayesPrint ("   would be equivalent to executing two commands:                                \n");
12055         MrBayesPrint ("                                                                                 \n");
12056         MrBayesPrint ("     mcmcp <setting parameters shared with mcmc>;                                \n");
12057         MrBayesPrint ("     ss <setting exclusive ss parameters>;                                       \n");
12058         MrBayesPrint ("                                                                                 \n");
12059         MrBayesPrint ("   For more information on the stepping-stone algorithm, see:                    \n");
12060         MrBayesPrint ("                                                                                 \n");
12061         MrBayesPrint ("   Xie, W., P. O. Lewis, Y. Fan, L. Kuo, and M.-H. Chen. 2011. Improving marginal\n");
12062         MrBayesPrint ("      likelihood estimation for Bayesian phylogenetic model selection. Systematic\n");
12063         MrBayesPrint ("      Biology 60:150-160.                                                        \n");
12064         MrBayesPrint ("                                                                                 \n");
12065         MrBayesPrint ("   Available options:                                                            \n");
12066         MrBayesPrint ("   (NB: Only exclusive ss parameters listed here. For additional parameters, see \n");
12067         MrBayesPrint ("        help on 'mcmc' or 'mcmcp'.                                               \n");
12068         MrBayesPrint ("                                                                                 \n");
12069         MrBayesPrint ("   Alpha        -- The beta values used in the stepping-stone sampling procedure \n");
12070         MrBayesPrint ("                   correspond to evenly spaced quantiles from a Beta('Alpha',1.0)\n");
12071         MrBayesPrint ("                   distribution. The parameter 'Alpha' determines the skewness of\n");
12072         MrBayesPrint ("                   the beta values. If 'Alpha' is set to '1.0', the beta values  \n");
12073         MrBayesPrint ("                   would be spaced uniformly on the interval (0.0,1.0). However, \n");
12074         MrBayesPrint ("                   better results are obtained if the beta values are skewed.    \n");
12075         MrBayesPrint ("                   Empirically, it was observed that 'Alpha' values in the range \n");
12076         MrBayesPrint ("                   of 0.3 to 0.5 produce the most accurate results.              \n");
12077         MrBayesPrint ("   Burninss     -- Fixed number of samples discarded before sampling of the first\n");
12078         MrBayesPrint ("                   step starts. 'Burninss' can be specified using either a pos-  \n");
12079         MrBayesPrint ("                   itive or a negative number. If the number is positive, it is  \n");
12080         MrBayesPrint ("                   interpreted as the number of samples to discard as burnin. If \n");
12081         MrBayesPrint ("                   the number is negative, its absolute value is interpreted as  \n");
12082         MrBayesPrint ("                   the length of the burnin in terms of the length of each of the\n");
12083         MrBayesPrint ("                   following steps in the stepping-stone algorithm. For instance,\n");
12084         MrBayesPrint ("                   a value of '-1' means that the length of the burnin is the    \n");
12085         MrBayesPrint ("                   same as the length of each of the subsequent steps.           \n");
12086         MrBayesPrint ("   Nsteps       -- Number of steps in the stepping-stone algorithm. Typically, a \n");
12087         MrBayesPrint ("                   number above 30 is sufficient for accurate results.           \n");
12088         MrBayesPrint ("   FromPrior    -- If it is set to 'Yes', it indicates that in the first step we \n"); 
12089         MrBayesPrint ("                   sample from the prior, with each consequtive step we sample   \n");
12090         MrBayesPrint ("                   closer to the posterior. 'No' indicates the opposite direction\n");
12091         MrBayesPrint ("                   of power posterior change, i.e. in the first step we sample   \n");
12092         MrBayesPrint ("                   close to the posterior, and with each consequtive step we     \n");
12093         MrBayesPrint ("                   sample closer to the prior.                                   \n");
12094         MrBayesPrint ("                                                                                 \n");
12095         MrBayesPrint ("   Current settings:                                                             \n");
12096         MrBayesPrint ("                                                                                 \n");
12097         MrBayesPrint ("   Parameter          Options               Current Setting                      \n");
12098         MrBayesPrint ("   --------------------------------------------------------                      \n");
12099         MrBayesPrint ("   Alpha              <number>              %1.2lf\n", chainParams.alphaSS);
12100         MrBayesPrint ("   BurninSS           <number>              %d\n", chainParams.burninSS);
12101         MrBayesPrint ("   Nsteps             <number>              %d\n", chainParams.numStepsSS);
12102         MrBayesPrint ("   FromPrior           Yes/No               %s                                   \n", chainParams.startFromPriorSS == YES ? "Yes" : "No");
12103         MrBayesPrint ("                                                                                 \n");
12104         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12105         }
12106 else if (!strcmp(helpTkn, "Ssp"))
12107         {
12108         // PrintYesNo (chainParams.saveBrlens, yesNoStr);
12109         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12110         MrBayesPrint ("   Ssp                                                                           \n");
12111         MrBayesPrint ("                                                                                 \n");
12112         MrBayesPrint ("   This command sets the parameters of the stepping-stone sampling               \n");
12113         MrBayesPrint ("   analysis without actually starting the chain. This command is identical       \n");
12114         MrBayesPrint ("   in all respects to Ss, except that the analysis will not start after          \n");
12115         MrBayesPrint ("   this command is issued. For more details on the options, check the help       \n");
12116         MrBayesPrint ("   menu for Ss.\n");
12117         MrBayesPrint ("                                                                                 \n");
12118         MrBayesPrint ("   Current settings:                                                             \n");
12119         MrBayesPrint ("                                                                                 \n");
12120         MrBayesPrint ("   Parameter          Options               Current Setting                      \n");
12121         MrBayesPrint ("   --------------------------------------------------------                      \n");
12122         MrBayesPrint ("   Alpha              <number>              %1.2lf\n", chainParams.alphaSS);
12123         MrBayesPrint ("   BurninSS           <number>              %d\n", chainParams.burninSS);
12124         MrBayesPrint ("   Nsteps             <number>              %d\n", chainParams.numStepsSS);
12125         MrBayesPrint ("   FromPrior           Yes/No               %s                                   \n", chainParams.startFromPriorSS == YES ? "Yes" : "No");
12126         MrBayesPrint ("                                                                                 \n");
12127         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12128         }
12129 else if (!strcmp(helpTkn, "Set"))
12130         {
12131         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12132         MrBayesPrint ("   Set                                                                           \n");
12133         MrBayesPrint ("                                                                                 \n");
12134         MrBayesPrint ("   This command is used to set some general features of the model or program     \n");
12135         MrBayesPrint ("   behavior. The correct usage is                                                \n");
12136         MrBayesPrint ("                                                                                 \n");
12137         MrBayesPrint ("      set <parameter>=<value> ... <parameter>=<value>                            \n");
12138         MrBayesPrint ("                                                                                 \n");
12139         MrBayesPrint ("   Available options:                                                            \n");
12140         MrBayesPrint ("                                                                                 \n");
12141         MrBayesPrint ("   Seed         -- Sets the seed number for the random number generator. The     \n");
12142         MrBayesPrint ("                   random number seed is initialized haphazardly at the beg-     \n");
12143         MrBayesPrint ("                   inning of each MrBayes session. This option allows you to     \n");
12144         MrBayesPrint ("                   set the seed to some specific value, thereby allowing you     \n");
12145         MrBayesPrint ("                   to exactly repeat an analysis. If the analysis uses swapping  \n");
12146         MrBayesPrint ("                   between cold and heated chains, you must also set the swap    \n");
12147         MrBayesPrint ("                   seed (see below) to exactly repeat the analysis.              \n");
12148         MrBayesPrint ("   Swapseed     -- Sets the seed used for generating the swapping sequence       \n");
12149         MrBayesPrint ("                   when Metropolis-coupled heated chains are used. This seed     \n");
12150         MrBayesPrint ("                   is initialized haphazardly at the beginning of each MrBayes   \n");
12151         MrBayesPrint ("                   session. This option allows you to set the seed to some       \n");
12152         MrBayesPrint ("                   specific value, thereby allowing you to exactly repeat a      \n");
12153         MrBayesPrint ("                   swap sequence. See also the 'Seed' option.                    \n");
12154         MrBayesPrint ("   Dir          -- The working directory. Specifies the absolute or relative path\n");
12155         MrBayesPrint ("                   to the working directory. If left empty, the working directory\n");
12156         MrBayesPrint ("                   is the current directory.                                     \n");
12157         MrBayesPrint ("   Partition    -- Set this option to a valid partition id, either the number or \n");
12158         MrBayesPrint ("                   name of a defined partition, to enforce a specific partition- \n");
12159         MrBayesPrint ("                   ing of the data. When a data matrix is read in, a partition   \n");
12160         MrBayesPrint ("                   called \"Default\" is automatically created. It divides the   \n");
12161         MrBayesPrint ("                   data into one part for each data type. If you only have one   \n");
12162         MrBayesPrint ("                   data type, DNA for instance, the default partition will not   \n");
12163         MrBayesPrint ("                   divide up the data at all. The default partition is always    \n");
12164         MrBayesPrint ("                   the first partition, so 'set partition=1' is the same as      \n");
12165         MrBayesPrint ("                   'set partition=default'.                                      \n");
12166         MrBayesPrint ("   Speciespartition -- Set this option to a valid speciespartition id, either the\n");
12167         MrBayesPrint ("                   number or name of a defined speciespartition, to enforce a    \n");
12168         MrBayesPrint ("                   specific partitioning of taxa to species. When a data matrix  \n");
12169         MrBayesPrint ("                   is read in, a speciespartition called \"Default\" is auto-    \n");
12170         MrBayesPrint ("                   matically created. It assigns one taxon for each species. The \n"); 
12171         MrBayesPrint ("                   default speciespartition is always the first speciespartition,\n");
12172         MrBayesPrint ("                   so 'set speciespartition=1' is the same as                    \n");
12173         MrBayesPrint ("                   'set speciespartition=default'.                               \n");
12174         MrBayesPrint ("   Autoclose    -- If autoclose is set to 'yes', then the program will not prompt\n");
12175         MrBayesPrint ("                   you during the course of executing a file. This is particular-\n");
12176         MrBayesPrint ("                   ly useful when you run MrBayes in batch mode.                 \n");
12177         MrBayesPrint ("   Nowarnings   -- If nowarnings is set to yes, then the program will not prompt \n");
12178         MrBayesPrint ("                   you when overwriting or appending an ouput file that is al-   \n");
12179         MrBayesPrint ("                   ready present. If 'nowarnings=no' (the default setting), then \n");
12180         MrBayesPrint ("                   the program propts the user before overwriting output files.  \n");
12181         MrBayesPrint ("   Autoreplace  -- When nowarnings is set to yes, then MrBayes will by default   \n");
12182         MrBayesPrint ("                   overwrite output files that already exists. This may cause    \n");
12183         MrBayesPrint ("                   irrecoverable loss of previous results if you have not removed\n");
12184         MrBayesPrint ("                   or renamed the files from previous runs. To override this be- \n");
12185         MrBayesPrint ("                   havior, set autoreplace to no, in which case new output will  \n");
12186         MrBayesPrint ("                   be appended to existing files instead.                        \n");
12187         MrBayesPrint ("   Quitonerror  -- If quitonerror is set to yes, then the program will quit when \n");
12188         MrBayesPrint ("                   an error is encountered, after printing an error message. If  \n");
12189         MrBayesPrint ("                   quitonerror is set to no (the default setting), then the      \n");
12190         MrBayesPrint ("                   program will wait for additional commands from the command    \n");
12191         MrBayesPrint ("                   line after the error message is printed.                      \n");
12192         MrBayesPrint ("   Scientific   -- Set this option to 'Yes' to write sampled values to file in   \n");
12193         MrBayesPrint ("                   scientific format and to 'No' to write them in fixed format.  \n");
12194         MrBayesPrint ("                   Fixed format is easier for humans to read but you risk losing \n");
12195         MrBayesPrint ("                   precision for small numbers. For instance, sampled values that\n");
12196         MrBayesPrint ("                   are less than 1E-6 will print to file as '0.000000' if fixed  \n");
12197         MrBayesPrint ("                   format is used and 'precision' is set to 6.                   \n");
12198         MrBayesPrint ("   Precision    -- Precision allows you to set the number of decimals to be prin-\n");
12199         MrBayesPrint ("                   ted when sampled values are written to file. Precision must be\n");
12200         MrBayesPrint ("                   in the range 3 to 15.                                         \n");
12201 #   if defined (BEAGLE_ENABLED)
12202         MrBayesPrint ("   Usebeagle    -- Set this option to 'Yes' to attempt to use the BEAGLE library \n");
12203         MrBayesPrint ("                   to compute the phylogenetic likelihood on a variety of high-  \n");
12204         MrBayesPrint ("                   performance hardware including multicore CPUs and GPUs. Some  \n"); 
12205         MrBayesPrint ("                   models in MrBayes are not yet supported by BEAGLE.            \n");               
12206         MrBayesPrint ("   Beagleresource -- Set this option to the number of a specific resource you    \n");
12207         MrBayesPrint ("                   wish to use with BEAGLE (use 'Showbeagle' to see the list of  \n");
12208         MrBayesPrint ("                   available resources). Set to '99' for auto-resource selection.\n");
12209         MrBayesPrint ("   Beagledevice -- Set this option to 'GPU' or 'CPU' to select processor.        \n"); 
12210         MrBayesPrint ("   Beagleprecision -- Selection 'Single' or 'Double' precision computation.      \n");
12211         MrBayesPrint ("   Beaglescaling -- 'Always' rescales partial likelihoods at each evaluation.    \n");
12212         MrBayesPrint ("                    'Dynamic' rescales less frequently and should run faster.    \n");
12213         MrBayesPrint ("   Beaglesse    -- Use SSE instructions on Intel CPU processors.                 \n");
12214         MrBayesPrint ("   Beagleopenmp -- Use OpenMP to parallelize across multi-core CPU processors.   \n");
12215 #   endif
12216 #   if defined (THREADS_ENABLED)
12217         MrBayesPrint ("   Beaglethreads -- Set this option to 'Yes' to employ multiple threads to drive \n");
12218         MrBayesPrint ("                   multiple BEAGLE resource simultaneously. This is highly       \n");
12219         MrBayesPrint ("                   recommended for more than one GPU, and for sufficiently large \n");
12220         MrBayesPrint ("                   data partitions, multi-core CPUs should also demonstrate      \n");
12221         MrBayesPrint ("                   speed-ups.                                                    \n");
12222 #   endif
12223         MrBayesPrint ("                                                                                 \n");
12224         MrBayesPrint ("   Current settings:                                                             \n");
12225         MrBayesPrint ("                                                                                 \n");
12226         MrBayesPrint ("   Parameter          Options               Current Setting                      \n");
12227         MrBayesPrint ("   --------------------------------------------------------                      \n");
12228         MrBayesPrint ("   Seed               <number>              %ld                                  \n", globalSeed);
12229         MrBayesPrint ("   Swapseed           <number>              %ld                                  \n", swapSeed);
12230         MrBayesPrint ("   Dir                <name>                \"%s\"\n", workingDir);
12231         if (defMatrix == YES)
12232             MrBayesPrint ("   Partition          <name>                %s\n", partitionNames[partitionNum]);
12233         else
12234             MrBayesPrint ("   Partition          <name>                \"\"\n");
12235         if (defTaxa == YES)
12236             MrBayesPrint ("   Speciespartition   <name>                %s\n", speciespartitionNames[speciespartitionNum]);
12237         else
12238             MrBayesPrint ("   Speciespartition   <name>                \"\"\n");
12239         MrBayesPrint ("   Autoclose          Yes/No                %s                                   \n", autoClose == YES ? "Yes" : "No");
12240         MrBayesPrint ("   Nowarnings         Yes/No                %s                                   \n", noWarn == YES ? "Yes" : "No");
12241         MrBayesPrint ("   Autoreplace        Yes/No                %s                                   \n", autoOverwrite == YES ? "Yes" : "No");
12242         MrBayesPrint ("   Quitonerror        Yes/No                %s                                   \n", quitOnError == YES ? "Yes" : "No");
12243         MrBayesPrint ("   Scientific         Yes/No                %s                                   \n", scientific == YES ? "Yes" : "No");
12244         MrBayesPrint ("   Precision          <number>              %d                                   \n", precision);
12245 #   if defined (BEAGLE_ENABLED)
12246         MrBayesPrint ("   Usebeagle          Yes/No                %s                                   \n", tryToUseBEAGLE == YES ? "Yes" : "No");
12247         MrBayesPrint ("   Beagleresource     <number>              %d                                   \n", beagleResourceNumber);
12248         MrBayesPrint ("   Beagledevice       CPU/GPU               %s                                   \n", beagleFlags & BEAGLE_FLAG_PROCESSOR_GPU ? "GPU" : "CPU");
12249         MrBayesPrint ("   Beagleprecision    Single/Double         %s                                   \n", beagleFlags & BEAGLE_FLAG_PRECISION_SINGLE ? "Single" : "Double");
12250         MrBayesPrint ("   Beaglescaling      Always/Dynamic        %s                                   \n", beagleScalingScheme == MB_BEAGLE_SCALE_ALWAYS ? "Always" : "Dynamic");
12251         MrBayesPrint ("   Beaglesse          Yes/No                %s                                   \n", beagleFlags & BEAGLE_FLAG_VECTOR_SSE ? "Yes" : "No");
12252         MrBayesPrint ("   Beagleopenmp       Yes/No                %s                                   \n", beagleFlags & BEAGLE_FLAG_THREADING_OPENMP ? "Yes" : "No");        
12253 #   endif
12254 #   if defined (THREADS_ENABLED)
12255         MrBayesPrint ("   Beaglethreads      Yes/No                %s                                   \n", tryToUseThreads == YES ? "Yes" : "No");
12256 #   endif
12257         MrBayesPrint ("                                                                                 \n");
12258         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12259         }
12260     else if (!strcmp(helpTkn, "Charset"))
12261         {
12262         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12263         MrBayesPrint ("   Charset                                                                       \n");
12264         MrBayesPrint ("                                                                                 \n");
12265         MrBayesPrint ("   This command defines a character set. The format for the charset command      \n"); 
12266         MrBayesPrint ("   is                                                                            \n"); 
12267         MrBayesPrint ("                                                                                 \n");
12268         MrBayesPrint ("      charset <name> = <character numbers>                                       \n"); 
12269         MrBayesPrint ("                                                                                 \n");
12270         MrBayesPrint ("   For example, \"charset first_pos = 1-720\\3\" defines a character set         \n");
12271         MrBayesPrint ("   called \"first_pos\" that includes every third site from 1 to 720.            \n");
12272         MrBayesPrint ("   The character set name cannot have any spaces in it. The slash (\\)           \n");
12273         MrBayesPrint ("   is a nifty way of telling the program to assign every third (or               \n");
12274         MrBayesPrint ("   second, or fifth, or whatever) character to the character set.                \n");
12275         MrBayesPrint ("   This option is best used not from the command line, but rather as a           \n");
12276         MrBayesPrint ("   line in the mrbayes block of a file. Note that you can use \".\" to           \n");
12277         MrBayesPrint ("   stand in for the last character (e.g., charset 1-.\\3).                       \n");
12278         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12279         }
12280     else if (!strcmp(helpTkn, "Outgroup"))
12281         {
12282         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12283         MrBayesPrint ("   Outgroup                                                                      \n");
12284         MrBayesPrint ("                                                                                 \n");
12285         MrBayesPrint ("   This command assigns a taxon to the outgroup. The correct usage is:           \n"); 
12286         MrBayesPrint ("                                                                                 \n");
12287         MrBayesPrint ("      outgroup <number>/<taxon name>                                             \n"); 
12288         MrBayesPrint ("                                                                                 \n");
12289         MrBayesPrint ("   For example, \"outgroup 3\" assigns the third taxon in the matrix to be       \n");
12290         MrBayesPrint ("   the outgroup. Similarly, \"outgroup Homo_sapiens\" assings the taxon          \n");
12291         MrBayesPrint ("   \"Homo_sapiens\" to be the outgroup (assuming that there is a taxon named     \n");
12292         MrBayesPrint ("   \"Homo_sapiens\" in the matrix). Only a single taxon can be assigned to       \n");
12293         MrBayesPrint ("   be the outgroup.                                                              \n");
12294         MrBayesPrint ("                                                                                 \n");
12295         if (defTaxa == YES)
12296             MrBayesPrint ("   Current outgroup: %s (taxon no. %d)\n", taxaNames[outGroupNum], outGroupNum+1);
12297         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12298         }
12299     else if (!strcmp(helpTkn, "Showusertrees"))
12300         {
12301         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12302         MrBayesPrint ("   Showusertrees                                                                 \n");
12303         MrBayesPrint ("                                                                                 \n");
12304         MrBayesPrint ("   This command shows the currently defined user trees. The correct usage        \n");
12305         MrBayesPrint ("   is \"showusertrees\".                                                         \n");
12306         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12307         }
12308     else if (!strcmp(helpTkn, "Showmcmctrees"))
12309         {
12310         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12311         MrBayesPrint ("   Showmcmctrees                                                                 \n");
12312         MrBayesPrint ("                                                                                 \n");
12313         MrBayesPrint ("   This command shows the current trees used by the Markov chains.               \n");
12314         MrBayesPrint ("   is \"showmcmctrees\".                                                         \n");
12315         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12316         }
12317     else if (!strcmp(helpTkn, "Deroot"))
12318         {
12319         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12320         MrBayesPrint ("   Deroot                                                                        \n");
12321         MrBayesPrint ("                                                                                 \n");
12322         MrBayesPrint ("   This command deroots the user tree. If the tree is already unrooted, a        \n");
12323         MrBayesPrint ("   warning is issued. The correct usage is \"deroot\".                           \n");
12324         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12325         }
12326     else if (!strcmp(helpTkn, "Root"))
12327         {
12328         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12329         MrBayesPrint ("   Root                                                                          \n");
12330         MrBayesPrint ("                                                                                 \n");
12331         MrBayesPrint ("   This command roots the tree. If the tree is already rooted, a warning         \n");
12332         MrBayesPrint ("   is issued. The tree is rooted at the midpoint between the outgroup species    \n");
12333         MrBayesPrint ("   and the ingroup species. The correct usage is \"root\".                       \n");
12334         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12335         }
12336     else if (!strcmp(helpTkn, "Taxset"))
12337         {
12338         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12339         MrBayesPrint ("   Taxset                                                                        \n");
12340         MrBayesPrint ("                                                                                 \n");
12341         MrBayesPrint ("   This command defines a taxon set. The format for the taxset command           \n"); 
12342         MrBayesPrint ("   is                                                                            \n"); 
12343         MrBayesPrint ("                                                                                 \n");
12344         MrBayesPrint ("      taxset <name> = <taxon names or numbers>                                   \n"); 
12345         MrBayesPrint ("                                                                                 \n");
12346         MrBayesPrint ("   For example, \"taxset apes = Homo Pan Gorilla Orang gibbon\" defines a        \n");
12347         MrBayesPrint ("   taxon set called \"apes\" that includes five taxa (namely, apes).             \n");
12348         MrBayesPrint ("   You can assign up to 30 taxon sets. This option is best used                  \n");
12349         MrBayesPrint ("   not from the command line but rather as a line in the mrbayes block           \n");
12350         MrBayesPrint ("   of a file.                                                                    \n");
12351         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12352         }
12353     else if (!strcmp(helpTkn, "Taxlabels"))
12354         {
12355         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12356         MrBayesPrint ("   Taxlabels                                                                     \n");
12357         MrBayesPrint ("                                                                                 \n");
12358         MrBayesPrint ("   This command defines taxon labels. It could be used within taxa block.        \n"); 
12359         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12360         }
12361     else if (!strcmp(helpTkn, "Charstat"))
12362         {
12363         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12364         MrBayesPrint ("   Charstat                                                                      \n");
12365         MrBayesPrint ("                                                                                 \n");
12366         MrBayesPrint ("   This command shows the status of all the characters. The correct usage        \n");
12367         MrBayesPrint ("   is                                                                            \n");
12368         MrBayesPrint ("                                                                                 \n");
12369         MrBayesPrint ("      charstat                                                                   \n");
12370         MrBayesPrint ("                                                                                 \n");
12371         MrBayesPrint ("   After typing \"charstat\", the character number, whether it is excluded       \n");
12372         MrBayesPrint ("   or included, and the partition identity are shown. The output is paused       \n");
12373         MrBayesPrint ("   every 100 characters. This pause can be turned off by setting autoclose       \n");
12374         MrBayesPrint ("   to \"yes\" (set autoclose=yes).                                               \n");
12375         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12376         }
12377     else if (!strcmp(helpTkn, "Taxastat"))
12378         {
12379         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12380         MrBayesPrint ("   Taxastat                                                                      \n");
12381         MrBayesPrint ("                                                                                 \n");
12382         MrBayesPrint ("   This command shows the status of all the taxa. The correct usage is           \n");
12383         MrBayesPrint ("                                                                                 \n");
12384         MrBayesPrint ("      taxastat                                                                   \n");
12385         MrBayesPrint ("                                                                                 \n");
12386         MrBayesPrint ("   After typing \"taxastat\", the taxon number, name, and whether it is          \n");
12387         MrBayesPrint ("   excluded or included are shown.                                               \n");
12388         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12389         }
12390     else if (!strcmp(helpTkn, "Partition"))
12391         {
12392         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12393         MrBayesPrint ("   Partition                                                                     \n");
12394         MrBayesPrint ("                                                                                 \n");
12395         MrBayesPrint ("   This command allows you to specify a character partition. The format for      \n"); 
12396         MrBayesPrint ("   this command is                                                               \n"); 
12397         MrBayesPrint ("                                                                                 \n");
12398         MrBayesPrint ("      partition <name> = <num parts>:<chars in first>, ...,<chars in last>       \n"); 
12399         MrBayesPrint ("                                                                                 \n");
12400         MrBayesPrint ("   For example, \"partition by_codon = 3:1st_pos,2nd_pos,3rd_pos\" specifies     \n"); 
12401         MrBayesPrint ("   a partition called \"by_codon\" which consists of three parts (first,         \n"); 
12402         MrBayesPrint ("   second, and third codon positions). Here, we are assuming that the sites      \n"); 
12403         MrBayesPrint ("   in each partition were defined using the charset command. You can specify     \n"); 
12404         MrBayesPrint ("   a partition without using charset as follows:                                 \n"); 
12405         MrBayesPrint ("                                                                                 \n");
12406         MrBayesPrint ("      partition by_codon = 3:1 4 6 9 12,2 5 7 10 13,3 6 8 11 14                  \n"); 
12407         MrBayesPrint ("                                                                                 \n");
12408         MrBayesPrint ("   However, we recommend that you use the charsets to define a set of char-      \n"); 
12409         MrBayesPrint ("   acters and then use these predefined sets when defining the partition.        \n"); 
12410         MrBayesPrint ("   Also, it makes more sense to define a partition as a line in the mrbayes      \n"); 
12411         MrBayesPrint ("   block than to issue the command from the command line (then again, you        \n"); 
12412         MrBayesPrint ("   may be a masochist, and want to do extra work).                               \n"); 
12413         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12414         }
12415     else if (!strcmp(helpTkn, "Exclude"))
12416         {
12417         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12418         MrBayesPrint ("   Exclude                                                                       \n");
12419         MrBayesPrint ("                                                                                 \n");
12420         MrBayesPrint ("   This command excludes characters from the analysis. The correct usage is      \n");
12421         MrBayesPrint ("                                                                                 \n");
12422         MrBayesPrint ("      exclude <number> <number> <number>                                         \n");
12423         MrBayesPrint ("                                                                                 \n");
12424         MrBayesPrint ("   or                                                                            \n");
12425         MrBayesPrint ("                                                                                 \n");
12426         MrBayesPrint ("      exclude <number> - <number>                                                \n");
12427         MrBayesPrint ("                                                                                 \n");
12428         MrBayesPrint ("   or                                                                            \n");
12429         MrBayesPrint ("                                                                                 \n");
12430         MrBayesPrint ("      exclude <charset>                                                          \n");
12431         MrBayesPrint ("                                                                                 \n");
12432         MrBayesPrint ("   or some combination thereof. Moreover, you can use the specifier \"\\\" to    \n");
12433         MrBayesPrint ("   exclude every nth character. For example, the following                       \n");
12434         MrBayesPrint ("                                                                                 \n");
12435         MrBayesPrint ("      exclude 1-100\\3                                                           \n");
12436         MrBayesPrint ("                                                                                 \n");
12437         MrBayesPrint ("   would exclude every third character. As a specific example,                   \n");
12438         MrBayesPrint ("                                                                                 \n");
12439         MrBayesPrint ("      exclude 2 3 10-14 22                                                       \n");
12440         MrBayesPrint ("                                                                                 \n");
12441         MrBayesPrint ("   excludes sites 2, 3, 10, 11, 12, 13, 14, and 22 from the analysis. Also,      \n");
12442         MrBayesPrint ("                                                                                 \n");
12443         MrBayesPrint ("      exclude all                                                                \n");
12444         MrBayesPrint ("                                                                                 \n");
12445         MrBayesPrint ("   excludes all of the characters from the analysis. Excluding all characters    \n");
12446         MrBayesPrint ("   does not leave you much information for inferring phylogeny.                  \n");
12447         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12448         }
12449     else if (!strcmp(helpTkn, "Include"))
12450         {
12451         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12452         MrBayesPrint ("   Include                                                                       \n");
12453         MrBayesPrint ("                                                                                 \n");
12454         MrBayesPrint ("   This command includes characters that were previously excluded from the       \n");
12455         MrBayesPrint ("   analysis. The correct usage is                                                \n");
12456         MrBayesPrint ("                                                                                 \n");
12457         MrBayesPrint ("      include <number> <number> <number>                                         \n");
12458         MrBayesPrint ("                                                                                 \n");
12459         MrBayesPrint ("   or                                                                            \n");
12460         MrBayesPrint ("                                                                                 \n");
12461         MrBayesPrint ("      include <number> - <number>                                                \n");
12462         MrBayesPrint ("                                                                                 \n");
12463         MrBayesPrint ("   or                                                                            \n");
12464         MrBayesPrint ("                                                                                 \n");
12465         MrBayesPrint ("      include <charset>                                                          \n");
12466         MrBayesPrint ("                                                                                 \n");
12467         MrBayesPrint ("   or some combination thereof. Moreover, you can use the specifier \"\\\" to    \n");
12468         MrBayesPrint ("   include every nth character. For example, the following                       \n");
12469         MrBayesPrint ("                                                                                 \n");
12470         MrBayesPrint ("      include 1-100\\3                                                           \n");
12471         MrBayesPrint ("                                                                                 \n");
12472         MrBayesPrint ("   would include every third character. As a specific example,                   \n");
12473         MrBayesPrint ("                                                                                 \n");
12474         MrBayesPrint ("      include 2 3 10-14 22                                                       \n");
12475         MrBayesPrint ("                                                                                 \n");
12476         MrBayesPrint ("   includes sites 2, 3, 10, 11, 12, 13, 14, and 22 from the analysis. Also,      \n");
12477         MrBayesPrint ("                                                                                 \n");
12478         MrBayesPrint ("      include all                                                                \n");
12479         MrBayesPrint ("                                                                                 \n");
12480         MrBayesPrint ("   includes all of the characters in the analysis. Including all of the          \n");
12481         MrBayesPrint ("   characters (even if many of them are bad) is a very total-evidence-like       \n");
12482         MrBayesPrint ("   thing to do. Doing this will make a certain group of people very happy.       \n");
12483         MrBayesPrint ("   On the other hand, simply using this program would make those same people     \n");
12484         MrBayesPrint ("   unhappy.                                                                      \n");
12485         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12486         }
12487     else if (!strcmp(helpTkn, "Delete"))
12488         {
12489         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12490         MrBayesPrint ("   Delete                                                                        \n");
12491         MrBayesPrint ("                                                                                 \n");
12492         MrBayesPrint ("   This command deletes taxa from the analysis. The correct usage is:            \n");
12493         MrBayesPrint ("                                                                                 \n");
12494         MrBayesPrint ("      delete <name and/or number and/or taxset> ...                              \n");
12495         MrBayesPrint ("                                                                                 \n");
12496         MrBayesPrint ("   A list of the taxon names or taxon numbers (labelled 1 to ntax in the order   \n");
12497         MrBayesPrint ("   in the matrix) or taxset(s) can be used.  For example, the following:         \n");
12498         MrBayesPrint ("                                                                                 \n");
12499         MrBayesPrint ("      delete 1 2 Homo_sapiens                                                    \n");
12500         MrBayesPrint ("                                                                                 \n");
12501         MrBayesPrint ("   deletes taxa 1, 2, and the taxon labelled Homo_sapiens from the analysis.     \n");
12502         MrBayesPrint ("   You can also use \"all\" to delete all of the taxa. For example,              \n");
12503         MrBayesPrint ("                                                                                 \n");
12504         MrBayesPrint ("      delete all                                                                 \n");
12505         MrBayesPrint ("                                                                                 \n");
12506         MrBayesPrint ("   deletes all of the taxa from the analysis. Of course, a phylogenetic anal-    \n");
12507         MrBayesPrint ("   ysis that does not include any taxa is fairly uninteresting.                  \n");
12508         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12509         }
12510     else if (!strcmp(helpTkn, "Restore"))
12511         {
12512         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12513         MrBayesPrint ("   Restore                                                                       \n");
12514         MrBayesPrint ("                                                                                 \n");
12515         MrBayesPrint ("   This command restores taxa to the analysis. The correct usage is:             \n");
12516         MrBayesPrint ("                                                                                 \n");
12517         MrBayesPrint ("      restore <name and/or number and/or taxset> ...                             \n");
12518         MrBayesPrint ("                                                                                 \n");
12519         MrBayesPrint ("   A list of the taxon names or taxon numbers (labelled 1 to ntax in the order   \n");
12520         MrBayesPrint ("   in the matrix) or taxset(s) can be used.  For example, the following:         \n");
12521         MrBayesPrint ("                                                                                 \n");
12522         MrBayesPrint ("      restore 1 2 Homo_sapiens                                                   \n");
12523         MrBayesPrint ("                                                                                 \n");
12524         MrBayesPrint ("   restores taxa 1, 2, and the taxon labelled Homo_sapiens to the analysis.      \n");
12525         MrBayesPrint ("   You can also use \"all\" to restore all of the taxa. For example,             \n");
12526         MrBayesPrint ("                                                                                 \n");
12527         MrBayesPrint ("      restore all                                                                \n");
12528         MrBayesPrint ("                                                                                 \n");
12529         MrBayesPrint ("   restores all of the taxa to the analysis.                                     \n");
12530         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12531         }
12532     else if (!strcmp(helpTkn, "Quit"))
12533         {
12534         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12535         MrBayesPrint ("   Quit                                                                          \n");
12536         MrBayesPrint ("                                                                                 \n");
12537         MrBayesPrint ("   This command quits the program. The correct usage is:                         \n");
12538         MrBayesPrint ("                                                                                 \n");
12539         MrBayesPrint ("      quit                                                                       \n");
12540         MrBayesPrint ("                                                                                 \n");
12541         MrBayesPrint ("   It is a very easy command to use properly.                                    \n");
12542         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12543         }
12544     else if (!strcmp(helpTkn, "Disclaimer"))
12545         {
12546         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12547         MrBayesPrint ("   Disclaimer                                                                    \n");
12548         MrBayesPrint ("                                                                                 \n");
12549         MrBayesPrint ("   This command shows the disclaimer for the program. In short, the disclaimer   \n");
12550         MrBayesPrint ("   states that the authors are not responsible for any silly things you may do   \n");
12551         MrBayesPrint ("   to your computer or any unforseen but possibly nasty things the computer      \n");
12552         MrBayesPrint ("   program may inadvertently do to you.                                          \n");
12553         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12554         }
12555     else if (!strcmp(helpTkn, "Unlink"))
12556         {
12557         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12558         MrBayesPrint ("   Unlink                                                                        \n");
12559         MrBayesPrint ("                                                                                 \n");
12560         MrBayesPrint ("   This command unlinks model parameters across partitions of the data. The      \n");
12561         MrBayesPrint ("   correct usage is:                                                             \n");
12562         MrBayesPrint ("                                                                                 \n");
12563         MrBayesPrint ("      unlink <parameter name> = (<all> or <partition list>)                      \n");
12564         MrBayesPrint ("                                                                                 \n");
12565         MrBayesPrint ("   A little background is necessary to understand this command. Upon exe-        \n");
12566         MrBayesPrint ("   cution of a file, a default partition is set up. This partition refer-        \n");
12567         MrBayesPrint ("   enced either by its name (\"default\") or number (0). If your data are        \n");
12568         MrBayesPrint ("   all of one type, then this default partition does not actually divide up      \n");
12569         MrBayesPrint ("   your characters. However, if your datatype is mixed, then the default         \n");
12570         MrBayesPrint ("   partition contains as many divisions as there are datatypes in your           \n");
12571         MrBayesPrint ("   character matrix. Of course, you can also define other partitions, and        \n");
12572         MrBayesPrint ("   switch among them using the set command (\"set partition=<name/number>\").    \n");
12573         MrBayesPrint ("   Importantly, you can also assign model parameters to individual part-         \n");
12574         MrBayesPrint ("   itions or to groups of them using the \"applyto\" option in lset and          \n");
12575         MrBayesPrint ("   prset. When the program attempts to perform an analysis, the model is         \n");
12576         MrBayesPrint ("   set for individual partitions. If the same parameter applies to differ-       \n");
12577         MrBayesPrint ("   partitions and if that parameter has the same prior, then the program         \n");
12578         MrBayesPrint ("   will link the parameters: that is, it will use a single value for the         \n");
12579         MrBayesPrint ("   parameter. The program's default, then, is to strive for parsimony.           \n");
12580         MrBayesPrint ("   However, there are lots of cases where you may want unlink a parameter        \n");
12581         MrBayesPrint ("   across partitions. For example, you may want a different transition/          \n");
12582         MrBayesPrint ("   transversion rate ratio to apply to different partitions. This command        \n");
12583         MrBayesPrint ("   allows you to unlink the parameters, or to make them different across         \n");
12584         MrBayesPrint ("   partitions. The converse of this command is \"link\", which links to-         \n");
12585         MrBayesPrint ("   gether parameters that were previously told to be different. The list         \n");
12586         MrBayesPrint ("   of parameters that can be unlinked includes:                                  \n");
12587         MrBayesPrint ("                                                                                 \n");
12588         MrBayesPrint ("      Tratio          -- Transition/transversion rate ratio                      \n");
12589         MrBayesPrint ("      Revmat          -- Substitution rates of GTR model                         \n");
12590         MrBayesPrint ("      Omega           -- Nonsynonymous/synonymous rate ratio                     \n");
12591         MrBayesPrint ("      Statefreq       -- Character state frequencies                             \n");
12592         MrBayesPrint ("      Shape           -- Gamma/LNorm shape parameter                             \n");
12593         MrBayesPrint ("      Pinvar          -- Proportion of invariable sites                          \n");
12594         MrBayesPrint ("      Correlation     -- Correlation parameter of autodiscrete gamma             \n");
12595         MrBayesPrint ("      Ratemultiplier  -- Rate multiplier for partitions                          \n");
12596         MrBayesPrint ("      Switchrates     -- Switching rates for covarion model                      \n");
12597         MrBayesPrint ("      Topology        -- Topology of tree                                        \n");
12598         MrBayesPrint ("      Brlens          -- Branch lengths of tree                                  \n");
12599         MrBayesPrint ("      Speciationrate  -- Speciation rates for birth-death process                \n");
12600         MrBayesPrint ("      Extinctionrate  -- Extinction rates for birth-death process                \n");
12601     //  MrBayesPrint ("   Fossilizationrate  -- Fossilization rates for fossilized birth-death process  \n");
12602         MrBayesPrint ("      Popsize         -- Population size for coalescence process                 \n");
12603         MrBayesPrint ("      Growthrate      -- Growth rate of coalescence process                      \n"); 
12604         MrBayesPrint ("      Aamodel         -- Aminoacid rate matrix                                   \n"); 
12605         MrBayesPrint ("      Cpprate         -- Rate of Compound Poisson Process (CPP)                  \n"); 
12606         MrBayesPrint ("      Cppmultdev      -- Standard dev. of CPP rate multipliers (log scale)       \n"); 
12607         MrBayesPrint ("      Cppevents       -- CPP events                                              \n"); 
12608         MrBayesPrint ("      TK02var         -- Variance increase in TK02 relaxed clock model           \n"); 
12609         MrBayesPrint ("      Igrvar          -- Variance increase in IGR relaxed clock model            \n");
12610         MrBayesPrint ("      Mixedvar        -- Variance increase in Mixed relaxed clock model          \n");
12611     //  MrBayesPrint ("      TK02branchrates -- Branch rates of TK02  relaxed clock model               \n");
12612     //  MrBayesPrint ("      Igrbranchrates  -- Branch rates of IGR   relaxed clock model               \n");
12613     //  MrBayesPrint ("      Mixedbrchrates  -- Branch rates of Mixed relaxed clock model               \n");
12614         MrBayesPrint ("                                                                                 \n");
12615         MrBayesPrint ("   For example,                                                                  \n");
12616         MrBayesPrint ("                                                                                 \n");
12617         MrBayesPrint ("      unlink shape=(all)                                                         \n");
12618         MrBayesPrint ("                                                                                 \n");
12619         MrBayesPrint ("   unlinks the gamma/lnorm shape parameter across all partitions of the data.    \n");
12620         MrBayesPrint ("   You can use \"showmodel\" to see the current linking status of the            \n");
12621         MrBayesPrint ("   characters.                                                                   \n");
12622         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12623         }
12624     else if (!strcmp(helpTkn, "Link"))
12625         {
12626         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12627         MrBayesPrint ("   Link                                                                          \n");
12628         MrBayesPrint ("                                                                                 \n");
12629         MrBayesPrint ("   This command links model parameters across partitions of the data. The        \n");
12630         MrBayesPrint ("   correct usage is:                                                             \n");
12631         MrBayesPrint ("                                                                                 \n");
12632         MrBayesPrint ("      link <parameter name> = (<all> or <partition list>)                        \n");
12633         MrBayesPrint ("                                                                                 \n");
12634         MrBayesPrint ("   The list of parameters that can be linked includes:                           \n");
12635         MrBayesPrint ("                                                                                 \n");
12636         MrBayesPrint ("      Tratio          -- Transition/transversion rate ratio                      \n");
12637         MrBayesPrint ("      Revmat          -- Substitution rates of GTR model                         \n");
12638         MrBayesPrint ("      Omega           -- Nonsynonymous/synonymous rate ratio                     \n");
12639         MrBayesPrint ("      Statefreq       -- Character state frequencies                             \n");
12640         MrBayesPrint ("      Shape           -- Gamma/LNorm shape parameter                             \n");
12641         MrBayesPrint ("      Pinvar          -- Proportion of invariable sites                          \n");
12642         MrBayesPrint ("      Correlation     -- Correlation parameter of autodiscrete gamma             \n");
12643         MrBayesPrint ("      Ratemultiplier  -- Rate multiplier for partitions                          \n");
12644         MrBayesPrint ("      Switchrates     -- Switching rates for covarion model                      \n");
12645         MrBayesPrint ("      Topology        -- Topology of tree                                        \n");
12646         MrBayesPrint ("      Brlens          -- Branch lengths of tree                                  \n");
12647         MrBayesPrint ("      Speciationrate  -- Speciation rates for birth-death process                \n");
12648         MrBayesPrint ("      Extinctionrate  -- Extinction rates for birth-death process                \n");
12649     //  MrBayesPrint ("   Fossilizationrate  -- Fossilization rates for fossilized birth-death process  \n");
12650         MrBayesPrint ("      Popsize         -- Population size for coalescence process                 \n");
12651         MrBayesPrint ("      Growthrate      -- Growth rate of coalescence process                      \n");
12652         MrBayesPrint ("      Aamodel         -- Aminoacid rate matrix                                   \n");
12653         MrBayesPrint ("      Cpprate         -- Rate of Compound Poisson Process (CPP)                  \n");
12654         MrBayesPrint ("      Cppmultdev      -- Standard dev. of CPP rate multipliers (log scale)       \n");
12655         MrBayesPrint ("      Cppevents       -- CPP events                                              \n");
12656         MrBayesPrint ("      TK02var         -- Variance increase in TK02 relaxed clock model           \n");
12657         MrBayesPrint ("      Igrvar          -- Variance increase in IGR relaxed clock model            \n");
12658         MrBayesPrint ("      Mixedvar        -- Variance increase in Mixed relaxed clock model          \n");
12659     //  MrBayesPrint ("      TK02branchrates -- Branch rates of TK02  relaxed clock model               \n");
12660     //  MrBayesPrint ("      Igrbranchrates  -- Branch rates of IGR   relaxed clock model               \n");
12661     //  MrBayesPrint ("      Mixedbrchrates  -- Branch rates of Mixed relaxed clock model               \n");
12662         MrBayesPrint ("                                                                                 \n");
12663         MrBayesPrint ("   For example,                                                                  \n");
12664         MrBayesPrint ("                                                                                 \n");
12665         MrBayesPrint ("      link shape=(all)                                                           \n");
12666         MrBayesPrint ("                                                                                 \n");
12667         MrBayesPrint ("   links the gamma/lnorm shape parameter across all partitions of the data.      \n");
12668         MrBayesPrint ("   You can use \"showmodel\" to see the current linking status of the            \n");
12669         MrBayesPrint ("   characters. For more information on this command, see the help menu           \n");
12670         MrBayesPrint ("   for link's converse, unlink (\"help unlink\");                                \n");
12671         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12672         }
12673     else if (!strcmp(helpTkn, "Help"))
12674         {
12675         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12676         MrBayesPrint ("   Help                                                                          \n");
12677         MrBayesPrint ("                                                                                 \n");
12678         MrBayesPrint ("   This command provides useful information on the use of this program. The      \n");
12679         MrBayesPrint ("   correct usage is                                                              \n");
12680         MrBayesPrint ("                                                                                 \n");
12681         MrBayesPrint ("      help                                                                       \n");
12682         MrBayesPrint ("                                                                                 \n");
12683         MrBayesPrint ("   which gives a list of all available commands with a brief description of      \n");
12684         MrBayesPrint ("   each or                                                                       \n");
12685         MrBayesPrint ("                                                                                 \n");
12686         MrBayesPrint ("      help <command>                                                             \n");
12687         MrBayesPrint ("                                                                                 \n");
12688         MrBayesPrint ("   which gives detailed information on the use of <command>.                     \n");
12689         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12690         }
12691     else if (!strcmp(helpTkn, "Sump"))
12692         {
12693         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12694         MrBayesPrint ("   Sump                                                                          \n");
12695         MrBayesPrint ("                                                                                 \n");
12696         MrBayesPrint ("   During an MCMC analysis, MrBayes prints the sampled parameter values to one or\n");
12697         MrBayesPrint ("   more tab-delimited text files, one for each independent run in your analysis. \n");
12698         MrBayesPrint ("   The command 'Sump' summarizes the information in this parameter file or these \n");
12699         MrBayesPrint ("   parameter files. By default, the root of the parameter file name(s) is assumed\n");
12700         MrBayesPrint ("   to be the name of the last matrix-containing nexus file. MrBayes also remem-  \n");
12701         MrBayesPrint ("   bers the number of independent runs in the last analysis that you set up, re- \n");
12702         MrBayesPrint ("   gardless of whether you actually ran it. For instance, if there were two in-  \n");
12703         MrBayesPrint ("   dependent runs, which is the initial setting when you read in a new matrix,   \n");
12704         MrBayesPrint ("   MrBayes will assume that there are two parameter files with the endings       \n");
12705         MrBayesPrint ("   '.run1.p' and '.run2.p'. You can change the root of the file names and the    \n");
12706         MrBayesPrint ("   number of runs using the 'Filename' and 'Nruns' settings.                     \n");
12707         MrBayesPrint ("                                                                                 \n");
12708         MrBayesPrint ("   When you invoke the 'Sump' command, three items are output: (1) a generation  \n");
12709         MrBayesPrint ("   plot of the likelihood values; (2) estimates of the marginal likelihood of    \n");
12710         MrBayesPrint ("   the model; and (3) a table with the mean, variance, and 95 percent credible   \n");
12711         MrBayesPrint ("   interval for the sampled parameters. All three items are output to screen.    \n");
12712         MrBayesPrint ("   The table of marginal likelihoods is also printed to a file with the ending   \n");
12713         MrBayesPrint ("   '.lstat' and the parameter table to a file with the ending '.pstat'. For some \n");
12714         MrBayesPrint ("   model parameters, there may also be a '.mstat' file.                          \n");
12715         MrBayesPrint ("                                                                                 \n");
12716         MrBayesPrint ("   When running 'Sump' you typically want to discard a specified number or       \n");
12717         MrBayesPrint ("   fraction of samples from the beginning of the chain as the burn in. This is   \n");
12718         MrBayesPrint ("   done using the same mechanism used by the 'mcmc' command. That is, if you     \n");
12719         MrBayesPrint ("   run an mcmc analysis with a relative burn in of 25 %% of samples for con-     \n");
12720         MrBayesPrint ("   vergence diagnostics, then the same burn in will be used for a subsequent     \n");
12721         MrBayesPrint ("   sump command, unless a different burn in is specified. That is, issuing       \n");
12722         MrBayesPrint ("                                                                                 \n");
12723         MrBayesPrint ("   sump                                                                          \n");
12724         MrBayesPrint ("                                                                                 \n");
12725         MrBayesPrint ("   immediately after 'mcmc', will result in using the same burn in settings as   \n");
12726         MrBayesPrint ("   for the 'mcmc' command. All burnin settings are reset to default values every \n");
12727         MrBayesPrint ("   time a new matrix is read in, namely relative burnin ('relburnin=yes') with   \n");
12728         MrBayesPrint ("   25 %% of samples discarded ('burninfrac = 0.25').                             \n");
12729         MrBayesPrint ("                                                                                 \n");
12730         MrBayesPrint ("   Options:                                                                      \n");
12731         MrBayesPrint ("                                                                                 \n");
12732         MrBayesPrint ("   Relburnin    -- If this option is set to 'Yes', then a proportion of the      \n");
12733         MrBayesPrint ("                   samples will be discarded as burnin when calculating summary  \n");
12734         MrBayesPrint ("                   statistics. The proportion to be discarded is set with        \n");
12735         MrBayesPrint ("                   'Burninfrac' (see below). When the 'Relburnin' option is set  \n");
12736         MrBayesPrint ("                   to 'No', then a specific number of samples is discarded       \n");
12737         MrBayesPrint ("                   instead. This number is set by 'Burnin' (see below). Note that\n");
12738         MrBayesPrint ("                   the burnin setting is shared across the 'sumt', 'sump', and   \n");
12739         MrBayesPrint ("                   'mcmc' commands.                                              \n");
12740         MrBayesPrint ("   Burnin       -- Determines the number of samples (not generations) that will  \n");
12741         MrBayesPrint ("                   be discarded when summary statistics are calculated. The      \n");
12742         MrBayesPrint ("                   value of this option is only applicable when 'Relburnin' is   \n");
12743         MrBayesPrint ("                   set to 'No'.                                                  \n");
12744         MrBayesPrint ("   Burninfrac   -- Determines the fraction of samples that will be discarded when\n");
12745         MrBayesPrint ("                   summary statistics are calculated. The setting only takes     \n");
12746         MrBayesPrint ("                   effect if 'Relburnin' is set to 'Yes'.                        \n");
12747         MrBayesPrint ("   Nruns        -- Determines how many '.p' files from independent analyses that \n");
12748         MrBayesPrint ("                   will be summarized. If Nruns > 1 then the names of the files  \n");
12749         MrBayesPrint ("                   are derived from 'Filename' by adding '.run1.p', '.run2.p',   \n");
12750         MrBayesPrint ("                   etc. If Nruns=1, then the single file name is obtained by     \n");
12751         MrBayesPrint ("                   adding '.p' to 'Filename'.                                    \n");
12752         MrBayesPrint ("   Filename     -- The name of the file to be summarized. This is the base of the\n");
12753         MrBayesPrint ("                   file name to which endings are added according to the current \n");
12754         MrBayesPrint ("                   setting of the 'Nruns' parameter. If 'Nruns' is 1, then only  \n");
12755         MrBayesPrint ("                   '.p' is added to the file name. Otherwise, the endings will   \n");
12756         MrBayesPrint ("                   be '.run1.p', '.run2.p', etc.                                 \n");
12757         MrBayesPrint ("   Outputname   -- Base name of the file(s) to which 'Sump' results will be      \n");
12758         MrBayesPrint ("                   printed.                                                      \n");
12759         MrBayesPrint ("   Hpd          -- Determines whether credibility intervals will be given as the \n");
12760         MrBayesPrint ("                   region of Highest Posterior Density ('Yes') or as the interval\n");
12761         MrBayesPrint ("                   containing the median 95 %% of sampled values ('No').         \n");
12762         MrBayesPrint ("   Minprob      -- Determines the minimum probability of submodels to be included\n");
12763         MrBayesPrint ("                   in summary statistics. Only applicable to models that explore \n");
12764         MrBayesPrint ("                   submodel spaces, like 'nst=mixed' and 'aamodelpr=mixed'.      \n");
12765         MrBayesPrint ("                                                                                 \n");
12766         MrBayesPrint ("   Current settings:                                                             \n");
12767         MrBayesPrint ("                                                                                 \n");
12768         MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
12769         MrBayesPrint ("   --------------------------------------------------------                      \n");
12770         MrBayesPrint ("   Relburnin       Yes/No                   %s                                   \n", chainParams.relativeBurnin == YES ? "Yes" : "No");
12771         MrBayesPrint ("   Burnin          <number>                 %d                                   \n", chainParams.chainBurnIn);
12772         MrBayesPrint ("   Burninfrac      <number>                 %1.2lf                               \n", chainParams.burninFraction);
12773         MrBayesPrint ("   Nruns           <number>                 %d                                   \n", sumpParams.numRuns);
12774         if (sumpParams.numRuns == 1)
12775             MrBayesPrint ("   Filename        <name>                   %s<.p>\n", sumpParams.sumpFileName);
12776         else
12777             MrBayesPrint ("   Filename        <name>                   %s<.run<i>.p>\n", sumpParams.sumpFileName);
12778         MrBayesPrint ("   Outputname      <name>                   %s<.pstat etc>\n", sumpParams.sumpOutfile);
12779         MrBayesPrint ("   Hpd             Yes/No                   %s                                   \n", sumpParams.HPD == YES ? "Yes" : "No");
12780         MrBayesPrint ("   Minprob         <number>                 %1.3lf                               \n", sumpParams.minProb);
12781         MrBayesPrint ("                                                                                 \n");
12782         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12783         }
12784     else if (!strcmp(helpTkn, "Sumss"))
12785         {
12786         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12787         MrBayesPrint ("   Sumss                                                                         \n");
12788         MrBayesPrint ("                                                                                 \n");
12789         MrBayesPrint ("   This command summarizes results of stepping stone analyses. It is a tool to   \n");
12790         MrBayesPrint ("   investigate the obtained results, and to help find the proper step burn-in.   \n");
12791         MrBayesPrint ("   To get more help information on stepping-stone analyses, use 'help ss'.       \n");
12792         MrBayesPrint ("                                                                                 \n");
12793         MrBayesPrint ("   During stepping-stone analysis, MrBayes collects the sampled likelihoods in   \n");
12794         MrBayesPrint ("   order to estimate the marginal likelihood at the end. It also prints the sam- \n");
12795         MrBayesPrint ("   pled parameter values to one or more tab-delimited text files, one for each   \n");
12796         MrBayesPrint ("   independent run in your analysis. The command 'Sumss' summarizes likelihood   \n");
12797         MrBayesPrint ("   values stored in these parameter files and calculates marginal likelihood es- \n");
12798         MrBayesPrint ("   timates. The names of the files that are summarized are exactly the same as   \n");
12799         MrBayesPrint ("   the names of the files used for the 'sump' command. In fact, the 'filename'   \n");
12800         MrBayesPrint ("   setting is a shared setting for the 'sump' and 'sumss' commands. That is, if  \n");
12801         MrBayesPrint ("   you change the setting in one of the commands, it would change the setting in \n");
12802         MrBayesPrint ("   the other command as well.                                                    \n");
12803         MrBayesPrint ("                                                                                 \n");
12804         MrBayesPrint ("   When you invoke the 'Sumss' command, three items are output: (1) 'Step contri-\n");
12805         MrBayesPrint ("   bution table' - summarizes the contribution of each step to the overall esti- \n");
12806         MrBayesPrint ("   mate; (2) 'Step plot' - plot of the likelihood values for the initial burn-in \n");
12807         MrBayesPrint ("   phase or a chosen step in the stepping-stone algorithm; (3) 'Joined plot' -   \n");
12808         MrBayesPrint ("   summarizes sampling across all steps in the algorithm.                        \n");
12809         MrBayesPrint ("                                                                                 \n");
12810         MrBayesPrint ("   Step contribution table                                                       \n");
12811         MrBayesPrint ("   The printed table is similar to the one output to the .ss file. The main pur- \n");
12812         MrBayesPrint ("   pose of the table is to summarize marginal likelihood for different values of \n");
12813         MrBayesPrint ("   the step burn-in after the stepping stone  analysis has finished. The burn-in \n");
12814         MrBayesPrint ("   is controlled by the 'Relburnin', 'Burnin' and 'Burninfrac' settings.         \n");
12815         MrBayesPrint ("   Note that during stepping-stone analyses, step contributions to marginal      \n");
12816         MrBayesPrint ("   likelihood are calculated based on all generations excluding burn-in. 'Sumss' \n");
12817         MrBayesPrint ("   on the other hand makes estimates based only on the sampled generations. This \n");
12818         MrBayesPrint ("   may lead to slight difference in results compared to the one printed to the   \n");
12819         MrBayesPrint ("   .ss file.                                                                     \n");
12820         MrBayesPrint ("                                                                                 \n");
12821         MrBayesPrint ("   Step plot                                                                     \n");
12822         MrBayesPrint ("   The main objective of the plot is to provide a close look at a given step in  \n");
12823         MrBayesPrint ("   the analysis. Which step is printed here is defined by the 'Steptoplot' set-  \n");
12824         MrBayesPrint ("   ting. The plot could be used to inspect if the chosen step burn-in is appro-  \n");
12825         MrBayesPrint ("   priate for the given step. It could also be used to check if the initial burn-\n");
12826         MrBayesPrint ("   in phase has converged. Note that the amount of discarded samples is controled\n");
12827         MrBayesPrint ("   by the 'Discardfrac' setting, and not by the ordinary burn-in settings.       \n");
12828         MrBayesPrint ("                                                                                 \n");
12829         MrBayesPrint ("   Joined plot                                                                   \n");
12830         MrBayesPrint ("   Different steps sample from different power posterior distributions. When we  \n");
12831         MrBayesPrint ("   switch from one distribution to another, it takes some number of generations  \n");
12832         MrBayesPrint ("   before the chain settles at the correct stationary distribution. This lag is  \n");
12833         MrBayesPrint ("   called a 'temperature lag' and if the corresponding samples are not removed,  \n");
12834         MrBayesPrint ("   it will result in a biased estimate. It is difficult to determine the lag be- \n");
12835         MrBayesPrint ("   forehand, but MrBayes allows you to explore different step burn-in settings   \n");
12836         MrBayesPrint ("   after you have finished the stepping-stone algorithm, without having to rerun \n");
12837         MrBayesPrint ("   the whole analysis. The 'Joined plot' helps to facilitate the choice of the   \n");
12838         MrBayesPrint ("   right step burn-in. The plot summarizes samples across all steps and gives you\n");
12839         MrBayesPrint ("   a quick overview of the whole analysis.                                       \n");
12840         MrBayesPrint ("                                                                                 \n");
12841         MrBayesPrint ("   Specifically, the following procedure is used to obtain the joined plot. Each \n");
12842         MrBayesPrint ("   step has the same number N of samples taken. We number each sample 1 to N     \n");
12843         MrBayesPrint ("   within steps according to the order in which the samples are taken. The first \n"); 
12844         MrBayesPrint ("   sample in each step is numbered 1, and the last sample is N. For each number i\n");
12845         MrBayesPrint ("   in [1,..., N], we sum up log likelihoods for all samples numbered i across all\n");
12846         MrBayesPrint ("   steps. The joined plot is a graph of the step number versus the normalized    \n");
12847         MrBayesPrint ("   sums we get in the procedure describe above. This directly visualizes the tem-\n");
12848         MrBayesPrint ("   perature lag and allows you to select the appropriate step burn-in.           \n");
12849         MrBayesPrint ("                                                                                 \n");
12850         MrBayesPrint ("   Ideally, after you discard the appropriate step burn-in, the graph should     \n");
12851         MrBayesPrint ("   appear as white noise around the estimated value. If you see an increasing or \n");
12852         MrBayesPrint ("   decreasing tendency in the beginning of the graph, you should increase the    \n");
12853         MrBayesPrint ("   step burn-in. If you see an increasing or decreasing tendency across the whole\n");
12854         MrBayesPrint ("   graph, then the initial burn-in phase was not long enough. In this case, you  \n");
12855         MrBayesPrint ("   need to rerun the analysis with a longer initial burn-in.                     \n");
12856         MrBayesPrint ("                                                                                 \n");
12857         MrBayesPrint ("   To make it easier to observe tendencies in the plotted graph you can choose   \n");
12858         MrBayesPrint ("   different levels of curve smoothing. If 'Smoothing' is set to k, it means that\n");
12859         MrBayesPrint ("   for each step i we take an average over step i and k neighboring samples in   \n");
12860         MrBayesPrint ("   both directions, i.e., the k-smoothed estimate for step i is an average over  \n");
12861         MrBayesPrint ("   values for steps [i-k,...,i+k].                                               \n");
12862         MrBayesPrint ("                                                                                 \n");
12863         MrBayesPrint ("                                                                                 \n");
12864         MrBayesPrint ("   Options:                                                                      \n");
12865         MrBayesPrint ("                                                                                 \n");
12866         MrBayesPrint ("   Allruns      -- If set to 'Yes', it forces all runs to be printed on the same \n");
12867         MrBayesPrint ("                   graph when drawing joined and step plots. If set to 'No', each\n");
12868         MrBayesPrint ("                   run is printed on a separat plot.                             \n");
12869         MrBayesPrint ("   Askmore      -- Long analyses may produce huge .p files. Reading in them may  \n");
12870         MrBayesPrint ("                   take several minutes. If you want to investigate different    \n");
12871         MrBayesPrint ("                   aspects of your analyses, it could be very inconvenient to    \n");
12872         MrBayesPrint ("                   wait for several minutes each time you want to get a new sum- \n");
12873         MrBayesPrint ("                   mary for different settings. If you set 'Askmore' to 'YES',   \n");
12874         MrBayesPrint ("                   sumss will read .p files only once. After responding to the   \n");
12875         MrBayesPrint ("                   original query, it will interactivaly ask you if you wish to  \n");
12876         MrBayesPrint ("                   produce more tables and plots for different settings of       \n");
12877         MrBayesPrint ("                   'Burnin' or 'Smoothing' (see below).                          \n");
12878         MrBayesPrint ("   Relburnin    -- If this option is set to 'Yes', then a proportion of the      \n");
12879         MrBayesPrint ("                   samples from each step will be discarded as burnin when calcu-\n");
12880         MrBayesPrint ("                   lsting summary statistics. The proportion to be discarded is  \n");
12881         MrBayesPrint ("                   set with 'Burninfrac' (see below). When the 'Relburnin' option\n");
12882         MrBayesPrint ("                   is set to 'No', then a specific number of samples is discarded\n");
12883         MrBayesPrint ("                   instead. This number is set by 'Burnin'. Note that the burnin \n");
12884         MrBayesPrint ("                   settings --- 'Relburnin', 'Burnin', and 'Burninfrac' --- are  \n");
12885         MrBayesPrint ("                   shared across the 'sumt', 'sump', 'sumss' and 'mcmc' commands.\n");
12886         MrBayesPrint ("   Burnin       -- Determines the number of samples (not generations) that will  \n");
12887         MrBayesPrint ("                   be discarded from each step when summary statistics are calcu-\n");
12888         MrBayesPrint ("                   lated. The value of this option is only applicable when       \n");
12889         MrBayesPrint ("                   'Relburnin' is set to 'No'.                                   \n");
12890         MrBayesPrint ("   Burninfrac   -- Determines the fraction of samples that will be discarded from\n");
12891         MrBayesPrint ("                   each step when summary statistics are calculated. The setting \n");
12892         MrBayesPrint ("                   only takes effect if 'Relburnin' is set to 'Yes'.             \n");
12893         MrBayesPrint ("   Discardfrac  -- Determines the fraction of samples that will be discarded when\n");
12894         MrBayesPrint ("                   a step plot is printed. It is similar to the 'Burninfrac' set-\n");
12895         MrBayesPrint ("                   ting, but unlike 'Burninfrac' it is used only for better vis- \n");
12896         MrBayesPrint ("                   ualization of the step plot. It has no effect on the number of\n");
12897         MrBayesPrint ("                   samples discarded during marginal likelihood computation.     \n");
12898         MrBayesPrint ("   Filename     -- The name of the file to be summarized. This is the base of the\n");
12899         MrBayesPrint ("                   file name to which endings are added according to the current \n");
12900         MrBayesPrint ("                   setting of the 'Nruns' parameter. If 'Nruns' is 1, then only  \n");
12901         MrBayesPrint ("                   '.p' is added to the file name. Otherwise, the endings will   \n");
12902         MrBayesPrint ("                   be '.run1.p', '.run2.p', etc. Note that the 'Filename' setting\n");
12903         MrBayesPrint ("                   is shared with 'sump' command.                                \n");
12904         MrBayesPrint ("   Nruns        -- Determines how many '.p' files from independent analyses that \n");
12905         MrBayesPrint ("                   will be summarized. If Nruns > 1 then the names of the files  \n");
12906         MrBayesPrint ("                   are derived from 'Filename' by adding '.run1.p', '.run2.p',   \n");
12907         MrBayesPrint ("                   etc. If Nruns=1, then the single file name is obtained by     \n");
12908         MrBayesPrint ("                   adding '.p' to 'Filename'.                                    \n");
12909         MrBayesPrint ("   Steptoplot   -- Defines which step will be printed in the step plot.If the    \n");
12910         MrBayesPrint ("                   value is set to 0, then the initial sample from the posterior \n");
12911         MrBayesPrint ("                   will be used.                                                 \n");
12912         MrBayesPrint ("   Smoothing    -- Determines smoothing of the joined plot (see above). A value  \n");
12913         MrBayesPrint ("                   equal to 0 results in no smoothing.                           \n");
12914         MrBayesPrint ("                                                                                 \n");
12915         MrBayesPrint ("   Current settings:                                                             \n");
12916         MrBayesPrint ("                                                                                 \n");
12917         MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
12918         MrBayesPrint ("   --------------------------------------------------------                      \n");
12919         MrBayesPrint ("   Allruns         Yes/No                   %s                                   \n", sumssParams.allRuns == YES ? "Yes" : "No");
12920         MrBayesPrint ("   Askmore         Yes/No                   %s                                   \n", sumssParams.askForMorePlots == YES ? "Yes" : "No");
12921         MrBayesPrint ("   Relburnin       Yes/No                   %s                                   \n", chainParams.relativeBurnin == YES ? "Yes" : "No");
12922         MrBayesPrint ("   Burnin          <number>                 %d                                   \n", chainParams.chainBurnIn);
12923         MrBayesPrint ("   Burninfrac      <number>                 %1.2lf                               \n", chainParams.burninFraction);
12924         MrBayesPrint ("   Discardfrac     <number>                 %1.2lf                               \n", sumssParams.discardFraction);
12925         if (sumpParams.numRuns == 1)
12926             MrBayesPrint ("   Filename        <name>                   %s<.p>\n", sumpParams.sumpFileName);
12927         else
12928             MrBayesPrint ("   Filename        <name>                   %s<.run<i>.p>\n", sumpParams.sumpFileName);        
12929         MrBayesPrint ("   Nruns           <number>                 %d                                   \n", sumpParams.numRuns);
12930         MrBayesPrint ("   Steptoplot      <number>                 %d                                   \n", sumssParams.stepToPlot);
12931         MrBayesPrint ("   Smoothing       <number>                 %d                                   \n", sumssParams.smoothing);
12932         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12933         }
12934     else if (!strcmp(helpTkn, "Comparetree"))
12935         {
12936         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12937         MrBayesPrint ("   Comparetree                                                                   \n");
12938         MrBayesPrint ("                                                                                 \n");
12939         MrBayesPrint ("   This command compares the trees in two files, called \"filename1\" and        \n");
12940         MrBayesPrint ("   \"filename2\". It will output a bivariate plot of the split frequencies       \n");
12941         MrBayesPrint ("   as well as plots of the tree distance as a function of the generation. The    \n");
12942         MrBayesPrint ("   plots can be used to get a quick indication of whether two runs have con-     \n");
12943         MrBayesPrint ("   verged onto the same set of trees. The \"Comparetree\" command will also      \n");
12944         MrBayesPrint ("   produce a \".pairs\" file and a \".dists\" file (these file endings are added \n");
12945         MrBayesPrint ("   to the end of the \"Outputname\"). The \".pairs\" file contains the paired    \n");
12946         MrBayesPrint ("   split frequencies from the two tree samples; the \".dists\" file contains the \n");
12947         MrBayesPrint ("   tree distance values.                                                         \n");
12948         MrBayesPrint ("                                                                                 \n");
12949         MrBayesPrint ("   Note that the \"Sumt\" command provides a different set of convergence diag-  \n");
12950         MrBayesPrint ("   nostics tools that you may also want to explore. Unlike \"Comparetree\",      \n");
12951         MrBayesPrint ("   \"Sumt\" can compare more than two tree samples and will calculate consensus  \n");
12952         MrBayesPrint ("   trees and split frequencies from the pooled samples.                          \n");
12953         MrBayesPrint ("                                                                                 \n");
12954         MrBayesPrint ("   Options:                                                                      \n");
12955         MrBayesPrint ("                                                                                 \n");
12956         MrBayesPrint ("   Relburnin     -- If this option is set to 'Yes', then a proportion of the     \n");
12957         MrBayesPrint ("                    samples will be discarded as burnin when calculating summary \n");
12958         MrBayesPrint ("                    statistics. The proportion to be discarded is set with       \n");
12959         MrBayesPrint ("                    Burninfrac (see below). When the Relburnin option is set to  \n");
12960         MrBayesPrint ("                    'No', then a specific number of samples is discarded instead.\n");
12961         MrBayesPrint ("                    This number is set by Burnin (see below). Note that the      \n");
12962         MrBayesPrint ("                    burnin setting is shared with the 'mcmc', 'sumt', 'sump' and \n");
12963         MrBayesPrint ("                    'plot' commands.                                             \n");
12964         MrBayesPrint ("   Burnin        -- Determines the number of samples (not generations) that will \n");
12965         MrBayesPrint ("                    be discarded when summary statistics are calculated. The     \n");
12966         MrBayesPrint ("                    value of this option is only relevant when Relburnin is set  \n");
12967         MrBayesPrint ("                    to 'No'.                                                     \n");
12968         MrBayesPrint ("   BurninFrac    -- Determines the fraction of samples that will be discarded    \n");
12969         MrBayesPrint ("                    when summary statistics are calculated. The value of this    \n");
12970         MrBayesPrint ("                    option is only relevant when Relburnin is set to 'Yes'.      \n");
12971         MrBayesPrint ("                    Example: A value for this option of 0.25 means that 25%% of  \n");
12972         MrBayesPrint ("                    the samples will be discarded.                               \n");
12973         MrBayesPrint ("   Minpartfreq   -- The minimum probability of partitions to include in summary  \n");
12974         MrBayesPrint ("                    statistics.                                                  \n");
12975         MrBayesPrint ("   Filename1     -- The name of the first tree file to compare.                  \n");
12976         MrBayesPrint ("   Filename2     -- The name of the second tree file to compare.                 \n");
12977         MrBayesPrint ("   Outputname    -- Name of the file to which 'comparetree' results will be      \n");
12978         MrBayesPrint ("                    printed.                                                     \n");
12979         MrBayesPrint ("                                                                                 \n");
12980         MrBayesPrint ("   Current settings:                                                             \n");
12981         MrBayesPrint ("                                                                                 \n");
12982         MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
12983         MrBayesPrint ("   --------------------------------------------------------                      \n");
12984         MrBayesPrint ("   Relburnin       Yes/No                   %s                                   \n", chainParams.relativeBurnin == YES ? "Yes" : "No");
12985         MrBayesPrint ("   Burnin          <number>                 %d                                   \n", chainParams.chainBurnIn);
12986         MrBayesPrint ("   Burninfrac      <number>                 %1.2lf                               \n", chainParams.burninFraction);
12987         MrBayesPrint ("   Minpartfreq     <number>                 %1.2lf                               \n", comptreeParams.minPartFreq);
12988         MrBayesPrint ("   Filename1       <name>                   %s                                   \n", comptreeParams.comptFileName1);
12989         MrBayesPrint ("   Filename2       <name>                   %s                                   \n", comptreeParams.comptFileName2);
12990         MrBayesPrint ("   Outputname      <name>                   %s                                   \n", comptreeParams.comptOutfile);
12991         MrBayesPrint ("                                                                                 \n");
12992         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12993         }
12994     else if (!strcmp(helpTkn, "Sumt"))
12995         {
12996         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
12997         MrBayesPrint ("   Sumt                                                                          \n");
12998         MrBayesPrint ("                                                                                 \n");
12999         MrBayesPrint ("   This command is used to produce summary statistics for trees sampled during   \n");
13000         MrBayesPrint ("   a Bayesian MCMC analysis. You can either summarize trees from one individual  \n");
13001         MrBayesPrint ("   analysis, or trees coming from several independent analyses. In either case,  \n");
13002         MrBayesPrint ("   all the sampled trees are read in and the proportion of the time any single   \n");
13003         MrBayesPrint ("   taxon bipartition (split) is found is counted. The proportion of the time that\n");
13004         MrBayesPrint ("   the bipartition is found is an approximation of the posterior probability of  \n");
13005         MrBayesPrint ("   the bipartition. (Remember that a taxon bipartition is defined by removing a  \n");
13006         MrBayesPrint ("   branch on the tree, dividing the tree into those taxa to the left and right   \n");
13007         MrBayesPrint ("   of the removed branch. This set is called a taxon bipartition.) The branch    \n");
13008         MrBayesPrint ("   length of the bipartition is also recorded, if branch lengths have been saved \n");
13009         MrBayesPrint ("   to file. The result is a list of the taxon bipartitions found, the frequency  \n");
13010         MrBayesPrint ("   with which they were found, the posterior probability of the bipartition      \n");
13011         MrBayesPrint ("   and, the mean and variance of the branch lengths or node depths, and various  \n");
13012         MrBayesPrint ("   other statistics.                                                             \n");
13013         MrBayesPrint ("                                                                                 \n");
13014         MrBayesPrint ("   The key to the partitions is output to a file with the suffix '.parts'. The   \n");
13015         MrBayesPrint ("   summary statistics pertaining to bipartition probabilities are output to a    \n");
13016         MrBayesPrint ("   file with the suffix '.tstat', and the statistics pertaining to branch or node\n");
13017         MrBayesPrint ("   parameters are output to a file with the suffix '.vstat'.                     \n");
13018         MrBayesPrint ("                                                                                 \n");
13019         MrBayesPrint ("   A consensus tree is also printed to a file with the suffix '.con.tre' and     \n");
13020         MrBayesPrint ("   printed to the screen as a cladogram, and as a phylogram if branch lengths    \n");
13021         MrBayesPrint ("   have been saved. The consensus tree is either a 50 percent majority rule tree \n");
13022         MrBayesPrint ("   or a majority rule tree showing all compatible partitions. If branch lengths  \n");
13023         MrBayesPrint ("   have been recorded during the run, the '.con.tre' file will contain a consen- \n");
13024         MrBayesPrint ("   sus tree with branch lengths and interior nodes labelled with support values. \n");
13025         MrBayesPrint ("   By default, the consensus tree will also contain other summary information in \n");
13026         MrBayesPrint ("   a format understood by the program 'FigTree'. To use a simpler format under-  \n");
13027         MrBayesPrint ("   stood by other tree-drawing programs, such as 'TreeView', set 'Conformat' to  \n");
13028         MrBayesPrint ("   'Simple'.                                                                     \n");
13029         MrBayesPrint ("                                                                                 \n");
13030         MrBayesPrint ("   MrBayes alo produces a file with the ending \".trprobs\" that contains a list \n");
13031         MrBayesPrint ("   of all the trees that were found during the MCMC analysis, sorted by their    \n");
13032         MrBayesPrint ("   probabilities. This list of trees can be used to construct a credible set of  \n");
13033         MrBayesPrint ("   trees. For example, if you want to construct a 95 percent credible set of     \n");
13034         MrBayesPrint ("   trees, you include all of those trees whose cumulative probability is less    \n");
13035         MrBayesPrint ("   than or equal to 0.95. You have the option of displaying the trees to the     \n");
13036         MrBayesPrint ("   screen using the \"Showtreeprobs\" option. The default is to not display the  \n");
13037         MrBayesPrint ("   trees to the screen; the number of different trees sampled by the chain can   \n");
13038         MrBayesPrint ("   be quite large. If you are analyzing a large set of taxa, you may actually    \n");
13039         MrBayesPrint ("   want to skip the calculation of tree probabilities entirely by setting        \n");
13040         MrBayesPrint ("   'Calctreeprobs' to 'No'.                                                      \n");
13041         MrBayesPrint ("                                                                                 \n");
13042         MrBayesPrint ("   When calculating summary statistics you probably want to skip those trees that\n");
13043         MrBayesPrint ("   were sampled in the initial part of the run, the so-called burn-in period. The\n");
13044         MrBayesPrint ("   number of skipped samples is controlled by the 'Relburnin', 'Burnin', and     \n");
13045         MrBayesPrint ("   'Burninfrac' settings, just as for the 'Mcmc' command. Since version 3.2.0,   \n");
13046         MrBayesPrint ("   the burn-in settings are shared across the 'Sumt', 'Sump' and 'Mcmc' commands.\n");
13047         MrBayesPrint ("   That is, changing the burn-in setting for one command will change the settings\n");
13048         MrBayesPrint ("   for subsequent calls to any of the other commands.                            \n");
13049         MrBayesPrint ("                                                                                 \n");
13050         MrBayesPrint ("   If you are summarizing the trees sampled in several independent analyses,     \n");
13051         MrBayesPrint ("   such as those resulting from setting the 'Nruns' option of the 'Mcmc' command \n");
13052         MrBayesPrint ("   to a value larger than 1, MrBayes will also calculate convergence diagnostics \n");
13053         MrBayesPrint ("   for the sampled topologies and branch lengths. These values can help you      \n");
13054         MrBayesPrint ("   determine whether it is likely that your chains have converged.               \n");
13055         MrBayesPrint ("                                                                                 \n");
13056         MrBayesPrint ("   The 'Sumt' command expands the 'Filename' according to the current values of  \n");
13057         MrBayesPrint ("   the 'Nruns' and 'Ntrees' options. For instance, if both 'Nruns' and 'Ntrees'  \n");
13058         MrBayesPrint ("   are set to 1, 'Sumt' will try to open a file named '<Filename>.t'. If 'Nruns' \n");
13059         MrBayesPrint ("   is set to 2 and 'Ntrees' to 1, then 'Sumt' will open two files, the first     \n");
13060         MrBayesPrint ("   named '<Filename>.run1.t' and the second '<Filename>.run2.t', etc. By default,\n");
13061         MrBayesPrint ("   the 'Filename' option is set such that 'Sumt' automatically summarizes all the\n");
13062         MrBayesPrint ("   results from your immediately preceding 'Mcmc' command. You can also use the  \n");
13063         MrBayesPrint ("   'Sumt' command to summarize tree samples in older analyses. If you want to do \n");
13064         MrBayesPrint ("   that, remember to first read in a matrix so that MrBayes knows what taxon     \n");
13065         MrBayesPrint ("   names to expect in the trees. Then set the 'Nruns', 'Ntrees' and 'Filename'   \n");
13066         MrBayesPrint ("   options appropriately if they differ from the MrBayes defaults.               \n");
13067         MrBayesPrint ("                                                                                 \n");
13068         MrBayesPrint ("   Options:                                                                      \n");
13069         MrBayesPrint ("                                                                                 \n");
13070         MrBayesPrint ("   Relburnin     -- If this option is set to YES, then a proportion of the       \n");
13071         MrBayesPrint ("                    samples will be discarded as burnin when calculating summary \n");
13072         MrBayesPrint ("                    statistics. The proportion to be discarded is set with       \n");
13073         MrBayesPrint ("                    Burninfrac (see below). When the Relburnin option is set to  \n");
13074         MrBayesPrint ("                    NO, then a specific number of samples is discarded instead.  \n");
13075         MrBayesPrint ("                    This number is set by Burnin (see below). Note that the      \n");
13076         MrBayesPrint ("                    burnin setting is shared across the 'sumt', 'sump', and      \n");
13077         MrBayesPrint ("                    'mcmc' commands.                                             \n");
13078         MrBayesPrint ("   Burnin        -- Determines the number of samples (not generations) that will \n");
13079         MrBayesPrint ("                    be discarded when summary statistics are calculated. The     \n");
13080         MrBayesPrint ("                    value of this option is only relevant when Relburnin is set  \n");
13081         MrBayesPrint ("                    to NO.                                                       \n");
13082         MrBayesPrint ("   BurninFrac    -- Determines the fraction of samples that will be discarded    \n");
13083         MrBayesPrint ("                    when summary statistics are calculated. The value of this    \n");
13084         MrBayesPrint ("                    option is only relevant when Relburnin is set to YES.        \n");
13085         MrBayesPrint ("                    Example: A value for this option of 0.25 means that 25%% of  \n");
13086         MrBayesPrint ("                    the samples will be discarded.                               \n");
13087         MrBayesPrint ("   Nruns         -- Determines how many '.t' files from independent analyses that\n");
13088         MrBayesPrint ("                    will be summarized. If Nruns > 1 then the names of the files \n");
13089         MrBayesPrint ("                    are derived from 'Filename' by adding '.run1.t', '.run2.t',  \n");
13090         MrBayesPrint ("                    etc. If Nruns=1 and Ntrees=1 (see below), then only '.t' is  \n");
13091         MrBayesPrint ("                    added to 'Filename'.                                         \n");
13092         MrBayesPrint ("   Ntrees        -- Determines how many trees there are in the sampled model. If \n");
13093         MrBayesPrint ("                    'Ntrees' > 1 then the names of the files are derived from    \n");
13094         MrBayesPrint ("                    'Filename' by adding '.tree1.t', '.tree2.t', etc. If there   \n");
13095         MrBayesPrint ("                    are both multiple trees and multiple runs, the filenames will\n");
13096         MrBayesPrint ("                    be '<Filename>.tree1.run1.t', '<Filename>.tree1.run2.t', etc.\n");
13097         MrBayesPrint ("   Filename      -- The name of the file(s) to be summarized. This is the base of\n");
13098         MrBayesPrint ("                    the file name, to which endings are added according to the   \n");
13099         MrBayesPrint ("                    current settings of the 'Nruns' and 'Ntrees' options.        \n");
13100         MrBayesPrint ("   Minpartfreq   -- The minimum probability of partitions to include in summary  \n");
13101         MrBayesPrint ("                    statistics.                                                  \n");
13102         MrBayesPrint ("   Contype       -- Type of consensus tree. 'Halfcompat' results in a 50%% major-\n");
13103         MrBayesPrint ("                    ity rule tree, 'Allcompat' adds all compatible groups to such\n");
13104         MrBayesPrint ("                    a tree.                                                      \n");
13105         MrBayesPrint ("   Conformat     -- Format of consensus tree. The 'Figtree' setting results in a \n");
13106         MrBayesPrint ("                    consensus tree formatted for the program FigTree, with rich  \n");
13107         MrBayesPrint ("                    summary statistics. The 'Simple' setting results in a simple \n");
13108         MrBayesPrint ("                    consensus tree written in a format read by a variety of pro- \n");
13109         MrBayesPrint ("                    grams.                                                       \n");
13110         MrBayesPrint ("   Outputname    -- Base name of the file(s) to which 'sumt' results will be     \n");
13111         MrBayesPrint ("                    printed. The default is the same as 'Filename'.              \n");
13112         MrBayesPrint ("   Calctreeprobs -- Determines whether tree probabilities should be calculated.  \n");
13113         MrBayesPrint ("   Showtreeprobs -- Determines whether tree probabilities should be displayed on \n");
13114         MrBayesPrint ("                    screen.                                                      \n");
13115         MrBayesPrint ("   Hpd           -- Determines whether credibility intervals will be given as the\n");
13116         MrBayesPrint ("                    region of Highest Posterior Density ('Yes') or as the inter- \n");
13117         MrBayesPrint ("                    val containing the median 95 %% of sampled values ('No').    \n");
13118         MrBayesPrint ("                                                                                 \n");
13119         MrBayesPrint ("   Current settings:                                                             \n");
13120         MrBayesPrint ("                                                                                 \n");
13121         MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
13122         MrBayesPrint ("   --------------------------------------------------------                      \n");
13123         MrBayesPrint ("   Relburnin       Yes/No                   %s                                   \n", chainParams.relativeBurnin == YES ? "Yes" : "No");
13124         MrBayesPrint ("   Burnin          <number>                 %d                                   \n", chainParams.chainBurnIn);
13125         MrBayesPrint ("   Burninfrac      <number>                 %1.2lf                               \n", chainParams.burninFraction);
13126         MrBayesPrint ("   Nruns           <number>                 %d                                   \n", sumtParams.numRuns);
13127         MrBayesPrint ("   Ntrees          <number>                 %d                                   \n", sumtParams.numTrees);
13128         if (sumtParams.numRuns == 1 && sumtParams.numTrees == 1)
13129             MrBayesPrint ("   Filename        <name>                   %s<.t>\n", sumtParams.sumtFileName);
13130         else if (sumtParams.numRuns == 1 && sumtParams.numTrees > 1)
13131             MrBayesPrint ("   Filename        <name>                   %s<.tree<i>.t>\n", sumtParams.sumtFileName);
13132         else if (sumtParams.numRuns > 1 && sumtParams.numTrees == 1)
13133             MrBayesPrint ("   Filename        <name>                   %s<.run<i>.t>\n", sumtParams.sumtFileName);
13134         else if (sumtParams.numRuns > 1 && sumtParams.numTrees > 1)
13135             MrBayesPrint ("   Filename        <name>                   %s<.tree<i>.run<i>.t>\n", sumtParams.sumtFileName);
13136         MrBayesPrint ("   Minpartfreq     <number>                 %1.2lf                               \n", sumtParams.minPartFreq);
13137         MrBayesPrint ("   Contype         Halfcompat/Allcompat     %s\n", sumtParams.sumtConType);
13138         MrBayesPrint ("   Conformat       Figtree/Simple           %s                                   \n", sumtParams.consensusFormat == SIMPLE ? "Simple" : "Figtree");
13139         MrBayesPrint ("   Outputname      <name>                   %s<.parts etc>\n", sumtParams.sumtOutfile);
13140         MrBayesPrint ("   Calctreeprobs   Yes/No                   %s                                   \n", sumtParams.calcTreeprobs == YES ? "Yes" : "No");
13141         MrBayesPrint ("   Showtreeprobs   Yes/No                   %s                                   \n", sumtParams.showSumtTrees == YES ? "Yes" : "No");
13142         MrBayesPrint ("   Hpd             Yes/No                   %s                                   \n", sumtParams.HPD == YES ? "Yes" : "No");
13143         MrBayesPrint ("                                                                                 \n");
13144         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13145         }
13146     else if (!strcmp(helpTkn, "Tree"))
13147         {
13148         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13149         MrBayesPrint ("   Tree                                                                          \n");
13150         MrBayesPrint ("                                                                                 \n");
13151         MrBayesPrint ("   This command is used by MrBayes to write trees to a nexus tree file. Trees    \n");
13152         MrBayesPrint ("   are written in the Newick format. For instance,                               \n");
13153         MrBayesPrint ("                                                                                 \n");
13154         MrBayesPrint ("      tree ((1,2),3,4);                                                          \n");
13155         MrBayesPrint ("                                                                                 \n");
13156         MrBayesPrint ("   describes an unrooted tree with taxa 1 and 2 being more closely related to    \n");
13157         MrBayesPrint ("   each other than to taxa 3 and 4. If branch lengths are saved to file, they    \n");
13158         MrBayesPrint ("   are given after a colon sign immediately following the terminal taxon or the  \n");
13159         MrBayesPrint ("   interior node they refer to. An example of an unrooted tree with branch       \n");
13160         MrBayesPrint ("   lengths is:                                                                   \n");
13161         MrBayesPrint ("                                                                                 \n");
13162         MrBayesPrint ("      tree ((1:0.064573,2:0.029042):0.041239,3:0.203988,4:0.187654);             \n");
13163         MrBayesPrint ("                                                                                 \n");
13164         MrBayesPrint ("   Trees that are rooted (clock trees) are written with a basal dichotomy        \n");
13165         MrBayesPrint ("   instead of a basal trichotomy. If the tree described above had been rooted    \n");
13166         MrBayesPrint ("   on the branch leading to taxon 4, it would have been represented as:          \n");
13167         MrBayesPrint ("                                                                                 \n");
13168         MrBayesPrint ("      tree (((1,2),3),4);                                                        \n");
13169         MrBayesPrint ("                                                                                 \n");
13170         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13171         }
13172     else if (!strcmp(helpTkn, "Report"))
13173         {
13174         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13175         MrBayesPrint ("   Report                                                                        \n");
13176         MrBayesPrint ("                                                                                 \n");
13177         MrBayesPrint ("   This command allows you to control how the posterior distribution is          \n");
13178         MrBayesPrint ("   reported. For rate parameters, it allows you to choose among several popular  \n");
13179         MrBayesPrint ("   parameterizations. The report command also allows you to request printing of  \n");
13180         MrBayesPrint ("   some model aspects that are usually not reported. For instance, if a node is  \n");
13181         MrBayesPrint ("   constrained in the analysis, MrBayes can print the probabilities of the       \n");
13182         MrBayesPrint ("   ancestral states at that node. Similarly, if there is rate variation in the   \n");
13183         MrBayesPrint ("   model, MrBayes can print the inferred site rates, and if there is omega varia-\n");
13184         MrBayesPrint ("   tion, MrBayes can print the inferred omega (positive selection) values for    \n");
13185         MrBayesPrint ("   each codon. In a complex model with several partitions, each partition is     \n");
13186         MrBayesPrint ("   controlled separately using the same 'Applyto' mechanism as in the 'Lset' and \n");
13187         MrBayesPrint ("   'Prset' commands.                                                             \n");
13188         MrBayesPrint ("                                                                                 \n");
13189         MrBayesPrint ("   Options:                                                                      \n");
13190         MrBayesPrint ("                                                                                 \n");
13191         MrBayesPrint ("   Applyto   -- This option allows you to apply the report commands to specific  \n");
13192         MrBayesPrint ("                partitions. This command should be the first in the list of      \n");
13193         MrBayesPrint ("                commands specified in 'report'.                                  \n");
13194         MrBayesPrint ("                For example,                                                     \n");
13195         MrBayesPrint ("                                                                                 \n");
13196         MrBayesPrint ("                   report applyto=(1,2) tratio=ratio                             \n");
13197         MrBayesPrint ("                                                                                 \n");
13198         MrBayesPrint ("                   report applyto=(3) tratio=dirichlet                           \n");
13199         MrBayesPrint ("                                                                                 \n");
13200         MrBayesPrint ("                would result in the transition and transversion rates of the     \n");
13201         MrBayesPrint ("                first and second partitions in the model being reported as a     \n");
13202         MrBayesPrint ("                ratio and the transition and transversion rates of the third     \n");
13203         MrBayesPrint ("                partition being reported as proportions of the rate sum (the     \n");
13204         MrBayesPrint ("                Dirichlet parameterization).                                     \n");
13205         MrBayesPrint ("   Tratio    -- This specifies the report format for the transition and trans-   \n");
13206         MrBayesPrint ("                version rates of a nucleotide substituion model with nst=2.      \n");
13207         MrBayesPrint ("                If 'ratio' is selected, the rates will be reported as a ratio    \n");
13208         MrBayesPrint ("                (transition rate/transversion rate). If 'dirichlet' is selected, \n");
13209         MrBayesPrint ("                the transition and transversion rates will instead be reported   \n");
13210         MrBayesPrint ("                as proportions of the rate sum. For example, if the transition   \n");
13211         MrBayesPrint ("                rate is three times the transversion rate and 'ratio' is selec-  \n");
13212         MrBayesPrint ("                ted, this will reported as a single value, '3.0'. If 'dirichlet' \n");
13213         MrBayesPrint ("                is selected instead, the same rates will be reported using two   \n");
13214         MrBayesPrint ("                values, '0.75 0.25'. The sum of the Dirichlet values is always 1.\n");
13215         MrBayesPrint ("                Although the Dirichlet format may be unfamiliar to some users,   \n");
13216         MrBayesPrint ("                it is more convenient for specifying priors than the ratio       \n");
13217         MrBayesPrint ("                format.                                                          \n");
13218         MrBayesPrint ("   Revmat    -- This specifies the report format for the substitution rates of   \n");
13219         MrBayesPrint ("                a GTR substitution model for nucleotide or amino acid data. If   \n");
13220         MrBayesPrint ("                'ratio' is selected, the rates will be reported scaled to the    \n");
13221         MrBayesPrint ("                G-T rate (for nucleotides) or the Y-V rate (for amino acids). If \n");
13222         MrBayesPrint ("                'dirichlet' is specified instead, the rates are reported as pro- \n");
13223         MrBayesPrint ("                portions of the rate sum. For instance, assume that the C-T rate \n");
13224         MrBayesPrint ("                is twice the A-G rate and four times the transversion rates,     \n");
13225         MrBayesPrint ("                which are equal. If the report format is set to 'ratio', this    \n");
13226         MrBayesPrint ("                would be reported as '1.0 2.0 1.0 1.0 4.0 1.0' since the rates   \n");
13227         MrBayesPrint ("                are reported in the order rAC, rAG, rAT, rCG, rCT, rGT and scaled\n");
13228         MrBayesPrint ("                relative to the last rate, the G-T rate. If 'dirichlet' is selec-\n");
13229         MrBayesPrint ("                ted instead, the same rates would have been reported as '0.1 0.2 \n");
13230         MrBayesPrint ("                0.1 0.1 0.4 0.1' since the rates are now scaled so that they sum \n");
13231         MrBayesPrint ("                to 1.0. The Dirichlet format is the parameterization used for    \n");
13232         MrBayesPrint ("                formulating priors on the rates.                                 \n");
13233         MrBayesPrint ("   Ratemult  -- This specifies the report format used for the rate multiplier of \n");
13234         MrBayesPrint ("                different model partitions. Three formats are available. If      \n");
13235         MrBayesPrint ("                'scaled' is selected, then rates are scaled such that the mean   \n");
13236         MrBayesPrint ("                rate per site across partitions is 1.0. If 'ratio' is chosen,    \n");
13237         MrBayesPrint ("                the rates are scaled relative to the rate of the first parti-    \n");
13238         MrBayesPrint ("                tion. Finally, if 'dirichlet' is chosen, the rates are given as  \n");
13239         MrBayesPrint ("                proportions of the rate sum. The latter is the format used       \n");
13240         MrBayesPrint ("                when formulating priors on the rate multiplier.                  \n");
13241         MrBayesPrint ("   Tree      -- This specifies the report format used for the tree(s). Two op-   \n");
13242         MrBayesPrint ("                tions are available. 'Topology' results in only the topology     \n");
13243         MrBayesPrint ("                being printed to file, whereas 'brlens' causes branch lengths to \n");
13244         MrBayesPrint ("                to be printed as well.                                           \n");
13245         MrBayesPrint ("   Ancstates -- If this option is set to 'yes', MrBayes will print the pro-      \n");
13246         MrBayesPrint ("                bability of the ancestral states at all constrained nodes. Typ-  \n");
13247         MrBayesPrint ("                ically, you are interested in the ancestral states of only a few \n");
13248         MrBayesPrint ("                characters and only at one node in the tree. To perform such     \n");
13249         MrBayesPrint ("                an analysis, first define and enforce a topology constraint      \n");
13250         MrBayesPrint ("                using 'constraint' and 'prset topologypr = constraints (...)'.   \n");
13251         MrBayesPrint ("                Then put the character(s) of interest in a separate partition and\n");
13252         MrBayesPrint ("                set MrBayes to report the ancestral states for that partition.   \n");
13253         MrBayesPrint ("                For instance, if the characters of interest are in partition 2,  \n");
13254         MrBayesPrint ("                use 'report applyto=(2) ancstates=yes' to force MrBayes to print \n");
13255         MrBayesPrint ("                the probability of the ancestral states of those characters at   \n");
13256         MrBayesPrint ("                the constrained node to the '.p' file.                           \n");
13257         MrBayesPrint ("   Siterates -- If this option is set to 'yes' and the relevant model has rate   \n");
13258         MrBayesPrint ("                variation across sites, then the site rates, weighted over rate  \n");
13259         MrBayesPrint ("                categories, will be reported to the '.p' file.                   \n");
13260         MrBayesPrint ("   Possel    -- If this option is set to 'yes' and the relevant model has omega  \n");
13261         MrBayesPrint ("                variation across sites, the probability that each model site     \n");
13262         MrBayesPrint ("                (codon in this case) is positively selected will be written to   \n");
13263         MrBayesPrint ("                file.                                                            \n");
13264         MrBayesPrint ("   Siteomega -- If this option is set to 'yes' and the relevant model has omega  \n");
13265         MrBayesPrint ("                variation across sites, the weighted omega value (over omega     \n");
13266         MrBayesPrint ("                categories) for each model site will be reported to file.        \n");
13267         MrBayesPrint ("                                                                                 \n");
13268         if (numCurrentDivisions == 0)
13269             tempInt = 1;
13270         else
13271             tempInt = numCurrentDivisions;
13272         for (i=0; i<tempInt; i++)
13273             {
13274             if (numCurrentDivisions == 0)
13275                 {
13276                 MrBayesPrint ("   Default report settings:                                                       \n");
13277                 mp = &defaultModel;
13278                 }
13279             else
13280                 {
13281                 MrBayesPrint ("   Current report settings for partition %d:                                              \n", i+1);
13282                 mp = &modelParams[i];
13283                 }
13284             MrBayesPrint ("                                                                                 \n");
13285             MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
13286             MrBayesPrint ("   --------------------------------------------------------                      \n");
13287             MrBayesPrint ("   Tratio          Ratio/Dirichlet          %s                                   \n", mp->tratioFormat);
13288             MrBayesPrint ("   Revmat          Ratio/Dirichlet          %s                                   \n", mp->revmatFormat);
13289             MrBayesPrint ("   Ratemult        Scaled/Ratio/Dirichlet   %s                                   \n", mp->ratemultFormat);
13290             MrBayesPrint ("   Tree            Brlens/Topology          %s                                   \n", mp->treeFormat);
13291             MrBayesPrint ("   Ancstates       Yes/No                   %s                                   \n", mp->inferAncStates);
13292             MrBayesPrint ("   Siterates       Yes/No                   %s                                   \n", mp->inferSiteRates);
13293             MrBayesPrint ("   Possel          Yes/No                   %s                                   \n", mp->inferPosSel);
13294             MrBayesPrint ("   Siteomega       Yes/No                   %s                                   \n", mp->inferSiteOmegas);
13295             MrBayesPrint ("                                                                                 \n");
13296             MrBayesPrint ("   ------------------------------------------------------------------            \n");       
13297             }
13298         }
13299     else if (!strcmp(helpTkn, "Manual"))
13300         {
13301         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13302         MrBayesPrint ("   Manual                                                                        \n");
13303         MrBayesPrint ("                                                                                 \n");
13304         MrBayesPrint ("   This command allows you to generate a text file containing help information   \n");
13305         MrBayesPrint ("   on all the available commands. This text file can be used as an up-to-date    \n");
13306         MrBayesPrint ("   command reference. You can set the name of the text file using the            \n");
13307         MrBayesPrint ("   \"filename\" option; the default is \"commref_mb<version>.txt\".              \n");
13308         MrBayesPrint ("                                                                                 \n");
13309         MrBayesPrint ("   Parameter       Options                  Current Setting                      \n");
13310         MrBayesPrint ("   --------------------------------------------------------                      \n");
13311         MrBayesPrint ("   Filename        <name>                   %s                                   \n", manFileName);
13312         MrBayesPrint ("                                                                                 \n");
13313         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13314         }
13315     else if (!strcmp(helpTkn, "Showmoves"))
13316         {
13317         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13318         MrBayesPrint ("   Showmoves                                                                     \n");
13319         MrBayesPrint ("                                                                                 \n");
13320         MrBayesPrint ("   This command shows the MCMC samplers (moves) that are switched on for the     \n");
13321         MrBayesPrint ("   parameters in the current model. The basic usage is                           \n");
13322         MrBayesPrint ("                                                                                 \n");
13323         MrBayesPrint ("      showmoves                                                                  \n");
13324         MrBayesPrint ("                                                                                 \n");
13325         MrBayesPrint ("   If you want to see all available moves, use                                   \n");
13326         MrBayesPrint ("                                                                                 \n");
13327         MrBayesPrint ("      showmoves allavailable=yes                                                 \n");
13328         MrBayesPrint ("                                                                                 \n");
13329         MrBayesPrint ("   If you want to change any of the tuning parameters for the moves, use the     \n");
13330         MrBayesPrint ("   'propset' command.                                                            \n");
13331         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13332         }
13333     else if (!strcmp(helpTkn, "Showparams"))
13334         {
13335         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13336         MrBayesPrint ("   Showparams                                                                    \n");
13337         MrBayesPrint ("                                                                                 \n");
13338         MrBayesPrint ("   This command shows all of the parameters in the current model. The basic      \n");
13339         MrBayesPrint ("   usage is                                                                      \n");
13340         MrBayesPrint ("                                                                                 \n");
13341         MrBayesPrint ("      showparams                                                                 \n");
13342         MrBayesPrint ("                                                                                 \n");
13343         MrBayesPrint ("   The parameters are listed together with their priors, the available moves,    \n");
13344         MrBayesPrint ("   and the current value(s), which will be used as the starting values in the    \n");
13345         MrBayesPrint ("   next mcmc analysis.                                                           \n");
13346         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13347         }
13348     else if (!strcmp(helpTkn, "Startvals"))
13349         {
13350         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13351         MrBayesPrint ("   Startvals                                                                     \n");
13352         MrBayesPrint ("                                                                                 \n");
13353         MrBayesPrint ("   Use this command to change the current values for parameters in your model.   \n");
13354         MrBayesPrint ("   These values will be used as the starting values in the next mcmc analysis.   \n");
13355         MrBayesPrint ("   The basic format is:                                                          \n");
13356         MrBayesPrint ("                                                                                 \n");
13357         MrBayesPrint ("      startvals <param>=(<value_1>,<value_2>,...,<value_n>)                      \n");
13358         MrBayesPrint ("                                                                                 \n");
13359         MrBayesPrint ("   for all substitution model parameters. The format is slightly different for   \n");
13360         MrBayesPrint ("   parameters that are written to a tree file:                                   \n");
13361         MrBayesPrint ("                                                                                 \n");
13362         MrBayesPrint ("      startvals <param>=<tree_name>                                              \n");
13363         MrBayesPrint ("                                                                                 \n");
13364         MrBayesPrint ("   This version of the command will look for a tree with the specified name      \n");
13365         MrBayesPrint ("   among the trees read in previously when parsing a tree block. The information \n");
13366         MrBayesPrint ("   stored in that tree will be used to set the starting value of the parameter.  \n");
13367         MrBayesPrint ("   The parameters that are set using this mechanism include topology and branch  \n");
13368         MrBayesPrint ("   length parameters, as well as relaxed clock branch rates, cpp events and      \n");
13369         MrBayesPrint ("   cpp branch rate multipliers.                                                  \n");
13370         MrBayesPrint ("                                                                                 \n");
13371         MrBayesPrint ("   The above versions of the command will set the value for all runs and chains. \n");
13372         MrBayesPrint ("   You can also set the value for an individual run and chain by using the format\n");
13373         MrBayesPrint ("                                                                                 \n");
13374         MrBayesPrint ("      startvals <param>(<run>,<chain>)=(<value_1>,...)                           \n");
13375         MrBayesPrint ("                                                                                 \n");
13376         MrBayesPrint ("   where <run> is the index of the run and <chain> the index of the chain. If    \n");
13377         MrBayesPrint ("   the run index is omitted, the values will be changed for all runs. Similarly, \n");
13378         MrBayesPrint ("   if the chain index is omitted, all chains will be set to the specified value. \n");
13379         MrBayesPrint ("   For example, if we wanted to set the values of the stationary frequency       \n");
13380         MrBayesPrint ("   parameter pi{1} to (0.1,0.1,0.4,0.4) for all chains in run 1, and to          \n");
13381         MrBayesPrint ("   (0.3,0.3,0.2,0.2) for chain 3 of run 2, we would use                          \n");
13382         MrBayesPrint ("                                                                                 \n");
13383         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");
13384         MrBayesPrint ("                                                                                 \n");
13385         MrBayesPrint ("   ---------------------------------------------------------------------------   \n");
13386         }
13387     else
13388         {
13389         return (ERROR);
13390         }
13391         
13392     return (NO_ERROR);
13393 }
13394
13395
13396 /* IsAmbig: This function returns YES if character is set as ambiguous
13397    either by using parenthetic notation or by ambiguity codes. It returns
13398    NO if character is unambiguous, missing or gapped */ 
13399 int IsAmbig (int charCode, int dType)
13400 {
13401     if (dType == DNA || dType == RNA || dType == STANDARD || dType == RESTRICTION || dType == PROTEIN)
13402         {
13403         if (charCode != MISSING && charCode != GAP)
13404             if (NBits(charCode) > 1)
13405                 return (YES);
13406         }
13407     else if (dType == CONTINUOUS)
13408         {
13409         /* do nothing, these cannot be partly ambiguous */
13410         }
13411     else
13412         {
13413         MrBayesPrint ("Unknown datatype in \"IsAmbig\"\n", spacer);
13414         }
13415
13416     return (NO);
13417 }
13418
13419
13420 int IsArgValid (char *tk, char *validArg)
13421 {
13422     int         i, j, k, tkLen, targetLen, numDiff, numStrMatches;
13423     char        tempStr[100];
13424     ParmInfoPtr p;
13425
13426     p = paramPtr;
13427     tkLen = (int) strlen(tk);
13428
13429     numStrMatches = i = j = 0;
13430     do
13431         {
13432         if (p->valueList[i] == '|' || p->valueList[i] == '\0')
13433             {
13434             tempStr[j++] = '\0';
13435             targetLen = (int) strlen(tempStr);
13436             if (tkLen <= targetLen)
13437                 {
13438                 numDiff = 0;
13439                 for (k=0; k<tkLen; k++)
13440                     if (ChangeCase(tk[k]) != ChangeCase(tempStr[k]))
13441                         numDiff++;
13442                 if (numDiff == 0)
13443                     {
13444                     numStrMatches++;
13445                     strcpy (validArg, tempStr);
13446                     }
13447                 }
13448             j = 0;
13449             }
13450         else
13451             tempStr[j++] = p->valueList[i];
13452         i++;
13453         }
13454     while (p->valueList[i] != '\0');
13455         
13456     if (numStrMatches == 0)
13457         {
13458         MrBayesPrint ("%s   No valid match for argument \"%s\"\n", spacer, tk);
13459         return (ERROR);
13460         }
13461     else if (numStrMatches == 1)
13462         {
13463         return (NO_ERROR);
13464         }
13465     else
13466         {
13467         MrBayesPrint ("%s   Argument \"%s\" is ambiguous\n", spacer, tk);
13468         return (ERROR);
13469         }
13470 }
13471
13472
13473 int IsIn (char ch, char *s)
13474 {
13475     while (*s)
13476         {
13477         if (*s++ == ch)
13478             return 1;
13479         }
13480     return 0;
13481 }
13482
13483
13484 int IsMissing (int charCode, int dType)
13485 {
13486     if (dType == DNA || dType == RNA)
13487         {
13488         if (charCode == 15 || charCode == 16)
13489             return (YES);
13490         }
13491     else if (dType == STANDARD || dType == PROTEIN)
13492         {
13493         if (charCode == MISSING || charCode == GAP)
13494             return (YES);
13495         }
13496     else if (dType == RESTRICTION)
13497         {
13498         if (charCode == 3 || charCode == 4)
13499             return (YES);
13500         }
13501     else if (dType == CONTINUOUS)
13502         {
13503
13504         }
13505     else
13506         {
13507         MrBayesPrint ("Unknown datatype in \"IsMissing\"\n", spacer);
13508         }
13509     return (NO);
13510 }
13511
13512
13513 int IsSame (char *s1, char *s2)
13514 {
13515     int         i, nDiff, isIdentical, len;
13516     
13517     isIdentical = YES;
13518     if (strlen(s1) != strlen(s2))
13519         isIdentical = NO; /* strings cannot be identical because they are different lengths */
13520     
13521     /* now, we go through both strings, one character at a time, to see if
13522        any are different */
13523     if (strlen(s1) > strlen(s2))
13524         len = (int) strlen(s2);
13525     else
13526         len = (int) strlen(s1);
13527     i = nDiff = 0;
13528     while (i < len)
13529         {
13530         if (tolower(s1[i]) != tolower(s2[i]))
13531             nDiff++;
13532         i++;
13533         }
13534     if (nDiff == 0 && isIdentical == YES)
13535         return (SAME);
13536     else if (nDiff == 0 && isIdentical == NO)
13537         return (CONSISTENT_WITH);
13538     else
13539         return (DIFFERENT);
13540 }
13541
13542
13543 int IsWhite (char c)
13544 {
13545     if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
13546         {
13547         if (c == '\n' || c == '\r')
13548             return 2;
13549         return 1;
13550         }
13551     return 0;
13552 }
13553
13554
13555 int NucID (char nuc)
13556 {
13557     char        n;
13558     
13559     if (nuc == 'U' || nuc == 'u')
13560         n = 'T';
13561     else
13562         n = nuc;
13563
13564     if (n == 'A' || n == 'a')
13565         {
13566         return 1;
13567         }
13568     else if (n == 'C' || n == 'c')
13569         {
13570         return 2;
13571         }
13572     else if (n == 'G' || n == 'g')
13573         {
13574         return 4;
13575         }
13576     else if (n == 'T' || n == 't')
13577         {
13578         return 8;
13579         }
13580     else if (n == 'R' || n == 'r')
13581         {
13582         return 5;
13583         }
13584     else if (n == 'Y' || n == 'y')
13585         {
13586         return 10;
13587         }
13588     else if (n == 'M' || n == 'm')
13589         {
13590         return 3;
13591         }
13592     else if (n == 'K' || n == 'k')
13593         {
13594         return 12;
13595         }
13596     else if (n == 'S' || n == 's')
13597         {
13598         return 6;
13599         }
13600     else if (n == 'W' || n == 'w')
13601         {
13602         return 9;
13603         }
13604     else if (n == 'H' || n == 'h')
13605         {
13606         return 11;
13607         }
13608     else if (n == 'B' || n == 'b')
13609         {
13610         return 14;
13611         }
13612     else if (n == 'V' || n == 'v')
13613         {
13614         return 7;
13615         }
13616     else if (n == 'D' || n == 'd')
13617         {
13618         return 13;
13619         }
13620     else if (n == 'N' || n == 'n')
13621         {
13622         return 15;
13623         }
13624     else if (n == gapId)
13625         {
13626         return GAP;
13627         }
13628     else if (n == missingId)
13629         {
13630         return MISSING;
13631         }
13632     else
13633         return -1;
13634 }
13635
13636
13637 /*-------| ParseCommand |------------------------------------------------
13638 |
13639 |   This function is used to parse a file. The expected format is:
13640 |   
13641 |      command parameter=value parameter=value ... ;
13642 |
13643 |   For example, the following is a valid line for this parser:
13644 |
13645 |      lset nst=2;
13646 |
13647 |   In some cases, however, the format is:
13648 |
13649 |      command stuff more stuff ... ;
13650 |
13651 |   For example, when reading a data file, the matrix command might be:
13652 |
13653 |      matrix
13654 |         taxon_1 data
13655 |         taxon_2 data
13656 |         taxon_3 data
13657 |         ;
13658 |
13659 |   Like before, the command and all of the stuff for that command are
13660 |   terminated by a semicolon.
13661 |
13662 */
13663 int ParseCommand (char *s)
13664 {
13665     int             rc, tokenType, inError, numMatches, skipCmd;
13666     char            errStr[100];
13667
13668     numMatches = 0;     /* Avoid gcc warnings (actually set in call to FindValidCommand) */
13669     cmdStr = s;
13670     tokenP = &s[0];
13671
13672 #   if defined (ECHO_PROCESSED_COMMANDS)
13673         MrBayesPrint ("Currently processing command: %s\n", s);
13674 #   endif
13675     
13676     inError = skipCmd = NO;
13677     do
13678         {
13679         /* Get the next token. A token is a valid word in a line. Token type is defined in "bayes.h". */
13680         if (GetToken (token, &tokenType, &tokenP))
13681             {
13682             inError = YES; 
13683             break;
13684             }
13685         if (strlen(token) > 0 || tokenType == ALPHA)
13686             {
13687 #           if defined (SHOW_TOKENS)
13688             MrBayesPrint ("%s\n", token);
13689 #           endif
13690             if (tokenType == LEFTCOMMENT)
13691                 {
13692                 /* If the token is a left comment "[", then we don't want to
13693                    actually process commands until we find a right comment.  */
13694                 /* The exception is if readComment is set to YES, in which case
13695                    we will leave it to the parser functions to decide on whether
13696                    they want to read the comment or not */
13697                 if (readComment == NO || inComment == YES)
13698                     {
13699                     inComment = YES;
13700                     numComments++;
13701                     }
13702                 }
13703             if (inComment == NO && inForeignBlock == NO)
13704                 {
13705                 if (tokenType != SEMICOLON)
13706                     {
13707                     /* If the token is not a semicolon, then we will be processing 
13708                        either a command or a parameter. */
13709                     if (expecting == Expecting(COMMAND))
13710                         {
13711                         /* We are expecting to find a command (defined above in "commands[]"). Find the 
13712                            correct command and set a pointer to that command. */
13713                         commandPtr = NULL;
13714                         if (FindValidCommand (token, &numMatches) == ERROR)
13715                             {
13716                             /* We couldn't find the command or the user did not specify enough letters
13717                                to unambiguously determine the command. The command pointer (commandPtr)
13718                                is NULL. */
13719                             if (numMatches == 0)    
13720                                 MrBayesPrint ("%s   Could not find command \"%s\"\n", spacer, token);
13721                             else 
13722                                 MrBayesPrint ("%s   Ambiguous command \"%s\"\n", spacer, token);
13723                             inError = YES;
13724                             }
13725                         else
13726                             {
13727                             /* We did find a valid command. Set what we are expecting to see next. */
13728                             expecting = commandPtr->expect;
13729                             
13730                             /* Check to see if we have one of the so-called special cases in which a 
13731                                command is not necessarily followed by a parameter (e.g., matrix). If we
13732                                do have a special case, then we want to set the parameter pointer (paramPtr)
13733                                appropriately. In this case, simply go to the first parameter in the parmList. */
13734                             if (commandPtr->specialCmd == YES)
13735                                 {
13736                                 isFirstMatrixRead = YES;
13737                                 foundFirst = NO;
13738                                 paramPtr = paramTable + commandPtr->parmList[0];
13739                                 }
13740                             if (strcmp(commandPtr->string, "Execute")==0)
13741                                 {
13742                                 /* set the tokenizer to recognize quoted strings */
13743                                 readWord = YES;
13744                                 }
13745                             }
13746                         }
13747                     else 
13748                         {
13749                         /* We are expecting to find a parameter or a value for the parameter, not a command. */
13750                         if ((expecting & Expecting(PARAMETER)) == Expecting(PARAMETER) && 
13751                             (expecting & Expecting(tokenType)) != Expecting(tokenType))
13752                             {
13753                             /* Specifically, if we are here, we need to go through the parameter list,
13754                                checking to see if the token is a valid parameter. */
13755                             expecting = (expecting & Expecting(PARAMETER));
13756                             if (FindValidParam (token, &numMatches) == ERROR)
13757                                 {
13758                                 /* The token is not a valid parameter. */
13759                                 if (numMatches == 0)
13760                                     MrBayesPrint ("%s   Could not find parameter \"%s\"\n", spacer, token);
13761                                 else 
13762                                     MrBayesPrint ("%s   Ambiguous parameter \"%s\"\n", spacer, token);
13763                                 inError = YES;
13764                                 }
13765                             else
13766                                 {
13767                                 /* The token is a valid parameter. Call the appropriate function ("DoXxxxParm"). */
13768                                 if ((paramPtr->fp)(paramPtr->string, token) == ERROR)
13769                                     {
13770                                     if (strcmp("Xxxxxxxxxx", paramPtr->string))
13771                                         MrBayesPrint ("%s   Error when setting parameter \"%s\" (1)\n", spacer, paramPtr->string);
13772                                     inError = YES;
13773                                     }
13774                                 }
13775                             }
13776                         else
13777                             {
13778                             /* Otherwise, we are expecting a value for the parameter. Call the appropriate function ("DoXxxxParm"). */
13779                             if ((expecting & Expecting(tokenType)) != 0)
13780                                 expecting = (expecting & Expecting(tokenType));
13781                             if ((Expecting(tokenType) & expecting) == Expecting(tokenType))
13782                                 {
13783                                 if ((paramPtr->fp)(paramPtr->string, token) == ERROR)
13784                                     {
13785                                     if (strcmp("Xxxxxxxxxx", paramPtr->string))
13786                                         MrBayesPrint ("%s   Error when setting parameter \"%s\" (2)\n", spacer, paramPtr->string);
13787                                     inError = YES;
13788                                     }
13789                                 }
13790                             else
13791                                 {
13792                                 inError = YES;
13793                                 WhatVariableExp (expecting, errStr);
13794                                 MrBayesPrint ("%s   Expecting '%s'\n", spacer, errStr+1);  /* there will be an initial space in errStr so print from pos 1 */
13795                                 if (numOpenExeFiles > 0)
13796                                     MrBayesPrint ("%s   Instead found '%s' in command '%s'\n",
13797                                         spacer, token, commandPtr->string);
13798                                 else
13799                                     MrBayesPrint ("%s   Instead found '%s' in command '%s' at position %d\n",
13800                                         spacer, token, commandPtr->string, tokenP - cmdStr - strlen(token)+1);
13801                                 }
13802                             }
13803                         }
13804                     }
13805                 else
13806                     {
13807                     /* The token is a semicolon. This means that we are at the end of processing one command. We
13808                        need to clean things up. We do this by calling the finishing function ("DoXxxx"). */
13809                     if ((Expecting(SEMICOLON) & expecting) == Expecting(SEMICOLON))
13810                         {
13811                         if (commandPtr->cmdFxnPtr != NULL)
13812                             {
13813                             /* Finish up the command here. */
13814                             rc = (commandPtr->cmdFxnPtr) ();
13815                             if (rc  == ERROR || rc == ABORT)
13816                                 {
13817                                 if (rc == ABORT)
13818                                     {
13819                                     MrBayesPrint ("   Mcmc run aborted\n");
13820                                     }
13821                                 else if (rc == SKIP_COMMAND)
13822                                     {
13823                                     MrBayesPrint ("   Cancelled execution of command\n");
13824                                     skipCmd = YES;
13825                                     }
13826                                 else
13827                                     {
13828                                     MrBayesPrint ("%s   Error in command \"%s\"\n", spacer, commandPtr->string);
13829                                     inError = YES;
13830                                     }
13831                                 }
13832                             }
13833                         /* if the user typed "quit", then we want to bail out of this loop, with a NO_ERROR_QUIT */
13834                         if (!strcmp(commandPtr->string, "Quit"))
13835                             return (NO_ERROR_QUIT);
13836                         expecting = Expecting(COMMAND);
13837                         }
13838                     else
13839                         {
13840                         inError = YES;
13841                         WhatVariableExp (expecting, errStr);
13842                         MrBayesPrint ("%s   Expecting %s\n", spacer, errStr);
13843                         }
13844                     }
13845                 }
13846             /* 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
13847                (e.g., a "paup" block) the terminating comment will be "end". */
13848             if (tokenType == RIGHTCOMMENT)
13849                 {
13850                 if (inComment == NO && readComment == NO)
13851                     {
13852                     MrBayesPrint ("%s   Found \"]\", without having previously found \"[\"\n", spacer);
13853                     inError = YES; 
13854                     }
13855                 else if (inComment == NO && readComment == YES)
13856                     {
13857                     /* This is OK, we just pass through and rely on the command to handle the RIGHTCOMMENT */
13858                     }
13859                 else
13860                     {
13861                     numComments--;
13862                     if (numComments == 0)
13863                         inComment = NO;
13864                     }
13865                 }
13866             if ((IsSame(token, "end") == SAME || IsSame(token, "endblock") == SAME) && inForeignBlock == YES)
13867                 {
13868                 strcpy (spacer, "");
13869                 inForeignBlock = NO;
13870                 }
13871             }
13872         
13873         } while ((*token || tokenType == ALPHA) && inError == NO && skipCmd == NO);
13874         
13875     if (inError == YES)
13876         {
13877         readComment = NO;   /* reset this in case it is set to YES in command and we get an error exit */
13878         return (ERROR);
13879         }
13880     else
13881         return (NO_ERROR);
13882 }
13883
13884
13885 void PrintSettings (char *command)
13886 {
13887     char yesNoStr[20];
13888
13889     if (!strcmp(command,"Mcmc"))
13890         {
13891         MrBayesPrint ("   Parameter       Options               Current Setting                         \n");
13892         MrBayesPrint ("   -----------------------------------------------------                         \n");
13893         MrBayesPrint ("   Ngen            <number>              %d                                      \n", chainParams.numGen);
13894         MrBayesPrint ("   Nruns           <number>              %d                                      \n", chainParams.numRuns);
13895         MrBayesPrint ("   Nchains         <number>              %d                                      \n", chainParams.numChains);
13896         MrBayesPrint ("   Temp            <number>              %lf                                     \n", chainParams.chainTemp);
13897         MrBayesPrint ("   Reweight        <number>,<number>     %1.2lf v %1.2lf ^                       \n", chainParams.weightScheme[0], chainParams.weightScheme[1]);
13898         MrBayesPrint ("   Swapfreq        <number>              %d                                      \n", chainParams.swapFreq);
13899         MrBayesPrint ("   Nswaps          <number>              %d                                      \n", chainParams.numSwaps);
13900         MrBayesPrint ("   Samplefreq      <number>              %d                                      \n", chainParams.sampleFreq);
13901         MrBayesPrint ("   Printfreq       <number>              %d                                      \n", chainParams.printFreq);
13902         PrintYesNo (chainParams.printAll, yesNoStr);
13903         MrBayesPrint ("   Printall        Yes/No                %s                                      \n", yesNoStr);
13904         MrBayesPrint ("   Printmax        <number>              %d                                      \n", chainParams.printMax);
13905         PrintYesNo (chainParams.mcmcDiagn, yesNoStr);
13906         MrBayesPrint ("   Mcmcdiagn       Yes/No                %s                                      \n", yesNoStr);
13907         MrBayesPrint ("   Diagnfreq       <number>              %d                                      \n", chainParams.diagnFreq);
13908         if (chainParams.diagnStat == AVGSTDDEV)
13909             strcpy (yesNoStr, "Avgstddev");
13910         else
13911             strcpy (yesNoStr, "Maxstddev");
13912         MrBayesPrint ("   Diagnstat       Avgstddev/Maxstddev   %s                                     \n", yesNoStr);
13913         MrBayesPrint ("   Minpartfreq     <number>              %1.2lf                                 \n", chainParams.minPartFreq);
13914         PrintYesNo (chainParams.allChains, yesNoStr);
13915         MrBayesPrint ("   Allchains       Yes/No                %s                                     \n", yesNoStr);
13916         PrintYesNo (chainParams.allComps, yesNoStr);
13917         MrBayesPrint ("   Allcomps        Yes/No                %s                                     \n", yesNoStr);
13918         PrintYesNo (chainParams.relativeBurnin, yesNoStr);
13919         MrBayesPrint ("   Relburnin       Yes/No                %s                                     \n", yesNoStr);
13920         MrBayesPrint ("   Burnin          <number>              %d                                     \n", chainParams.chainBurnIn);
13921         MrBayesPrint ("   Burninfrac      <number>              %1.2lf                                 \n", chainParams.burninFraction);
13922         PrintYesNo (chainParams.stopRule, yesNoStr);
13923         MrBayesPrint ("   Stoprule        Yes/No                %s                                     \n", yesNoStr);
13924         MrBayesPrint ("   Stopval         <number>              %1.2lf                                 \n", chainParams.stopVal);
13925         PrintYesNo (chainParams.saveTrees, yesNoStr);
13926         MrBayesPrint ("   Savetrees       Yes/No                %s                                     \n", yesNoStr);
13927         PrintYesNo (chainParams.checkPoint, yesNoStr);
13928         MrBayesPrint ("   Checkpoint      Yes/No                %s                                     \n", yesNoStr);
13929         MrBayesPrint ("   Checkfreq       <number>              %d                                     \n", chainParams.checkFreq);
13930         MrBayesPrint ("   Filename        <name>                %s.<p/t>\n", chainParams.chainFileName);
13931         MrBayesPrint ("   Startparams     Current/Reset         %s                                     \n", chainParams.startParams);
13932         MrBayesPrint ("   Starttree       Current/Random/       %s                                     \n", chainParams.startTree);
13933         MrBayesPrint ("                   Parsimony                                                    \n");
13934         MrBayesPrint ("   Nperts          <number>              %d                                     \n", chainParams.numStartPerts);
13935         PrintYesNo (chainParams.runWithData, yesNoStr);
13936         MrBayesPrint ("   Data            Yes/No                %s                                     \n", yesNoStr);
13937         MrBayesPrint ("   Ordertaxa       Yes/No                %s                                     \n", chainParams.orderTaxa == YES? "Yes" : "No");
13938         MrBayesPrint ("   Append          Yes/No                %s                                     \n", chainParams.append == YES? "Yes" : "No");
13939         MrBayesPrint ("   Autotune        Yes/No                %s                                     \n", chainParams.autotune == YES? "Yes" : "No");
13940         MrBayesPrint ("   Tunefreq        <number>              %d                                     \n", chainParams.tuneFreq);
13941         MrBayesPrint ("                                                                                \n");
13942         }
13943 }
13944
13945
13946 void PrintYesNo (int yn, char s[4])
13947 {
13948     if (yn == YES)
13949         strcpy (s, "Yes");
13950     else
13951         strcpy (s, "No");
13952 }
13953
13954
13955 int ProtID (char aa)
13956 {
13957     if (aa == 'A' || aa == 'a')      /* Ala */
13958         {
13959         return 1;
13960         }
13961     else if (aa == 'R' || aa == 'r') /* Arg */
13962         {
13963         return 2;
13964         }
13965     else if (aa == 'N' || aa == 'n') /* Asn */
13966         {
13967         return 4;
13968         }
13969     else if (aa == 'D' || aa == 'd') /* Asp */
13970         {
13971         return 8;
13972         }
13973     else if (aa == 'C' || aa == 'c') /* Cys */
13974         {
13975         return 16;
13976         }
13977     else if (aa == 'Q' || aa == 'q') /* Gln */
13978         {
13979         return 32;
13980         }
13981     else if (aa == 'E' || aa == 'e') /* Glu */
13982         {
13983         return 64;
13984         }
13985     else if (aa == 'G' || aa == 'g') /* Gly */
13986         {
13987         return 128;
13988         }
13989     else if (aa == 'H' || aa == 'h') /* His */
13990         {
13991         return 256;
13992         }
13993     else if (aa == 'I' || aa == 'i') /* Ile */
13994         {
13995         return 512;
13996         }
13997     else if (aa == 'L' || aa == 'l') /* Leu */
13998         {
13999         return 1024;
14000         }
14001     else if (aa == 'K' || aa == 'k') /* Lys */
14002         {
14003         return 2048;
14004         }
14005     else if (aa == 'M' || aa == 'm') /* Met */
14006         {
14007         return 4096;
14008         }
14009     else if (aa == 'F' || aa == 'f') /* Phe */
14010         {
14011         return 8192;
14012         }
14013     else if (aa == 'P' || aa == 'p') /* Pro */
14014         {
14015         return 16384;
14016         }
14017     else if (aa == 'S' || aa == 's') /* Ser */
14018         {
14019         return 32768;
14020         }
14021     else if (aa == 'T' || aa == 't') /* Thr */
14022         {
14023         return 65536;
14024         }
14025     else if (aa == 'W' || aa == 'w') /* Trp */
14026         {
14027         return 131072;
14028         }
14029     else if (aa == 'Y' || aa == 'y') /* Tyr */
14030         {
14031         return 262144;
14032         }
14033     else if (aa == 'V' || aa == 'v') /* Val */
14034         {
14035         return 524288;
14036         }
14037     else if (aa == 'X' || aa == 'x') /* Nonidentified */
14038         {
14039         return MISSING;
14040         }
14041     else if (aa == gapId)
14042         {
14043         return GAP;
14044         }
14045     else if (aa == missingId)
14046         {
14047         return MISSING;
14048         }
14049     else
14050         return -1;
14051 }
14052
14053
14054 int RemoveLastFromString (char *s1)
14055 {
14056     int     i, j, numPrev, numRemoved;
14057     
14058     /* We remove the last name from the string simply by deleting the last "|". */
14059        
14060     i = numPrev = 0;
14061     while (s1[i] != '\0')
14062         {
14063         if (s1[i] == '|')
14064             numPrev++;
14065         i++;
14066         }
14067         
14068     i = j = numRemoved = 0;
14069     while (s1[i] != '\0')
14070         {
14071         if (s1[i] == '|')
14072             j++;
14073         if (numPrev == j)
14074             {
14075             s1[i] = ' ';
14076             numRemoved++;
14077             break;
14078             }
14079         i++;
14080         }
14081
14082     if (numRemoved != 1)
14083         {
14084         MrBayesPrint ("%s   Could not find name to remove\n", spacer);
14085         return (ERROR);
14086         }
14087
14088     return (NO_ERROR);
14089 }
14090
14091
14092 int MBResID (char nuc)
14093 {
14094     char        n;
14095     
14096     n = nuc;
14097
14098     if (n == '0' || n == 'a' || n == 'A')
14099         {
14100         return 1;
14101         }
14102     else if (n == '1' || n == 'b' || n == 'B')
14103         {
14104         return 2;
14105         }
14106     else if (n == gapId)
14107         {
14108         return GAP;
14109         }
14110     else if (n == missingId)
14111         {
14112         return MISSING;
14113         }
14114     else
14115         return -1;
14116 }
14117
14118
14119 /* Reset character flags */
14120 void ResetCharacterFlags (void)
14121 {
14122     /* reset all characters flags */
14123     numChar              = 0;                        /* number of defined characters                  */
14124     defChars             = NO;                       /* flag for whether number of characters is known*/
14125     defMatrix            = NO;                       /* flag for whether matrix is successfull read   */
14126     matrixHasPoly        = NO;                       /* flag for whether matrix has polymorphisms     */
14127     isInAmbig            = NO;                       /* flag for whether the parser is within ()      */
14128     isInPoly             = NO;                       /* flag for whether the parser is within {}      */
14129     defPartition         = NO;                       /* flag for whether character partition is read  */
14130     defPairs             = NO;                       /* flag indicating whether pairs have been defnd */
14131     numDefinedPartitions = 0;                        /* number of defined partitions                  */
14132     partitionNum         = 0;                        /* partition number currently enforced           */
14133     numCurrentDivisions  = 0;                        /* number of partitions of data                  */
14134     numCharSets          = 0;                        /* holds number of character sets                */
14135     numDivisions         = 1;                        /* holds number of partitions                    */
14136     isMixed              = NO;                       /* are data mixed ?                              */
14137     dataType             = NONE;                     /* holds datatype                                */
14138     matchId              = '\0';                     /* no default for match character                */
14139     gapId                = '\0';                     /* no default for gap character                  */
14140     missingId            = '\0';                     /* no default for missing characters             */
14141 }
14142
14143
14144 /* Reset taxa flags */
14145 void ResetTaxaFlags (void)
14146 {
14147     numTaxa                 = 0;                         /* number of taxa                                */
14148     numNamedTaxa            = 0;                         /* number of named taxa                          */
14149     defTaxa                 = NO;                        /* flag for whether number of taxa is known      */
14150     isTaxsetDef             = NO;                        /* is a taxlabels set defined                    */
14151     numDefinedConstraints   = 0;                         /* holds number of defined constraints           */
14152     definedConstraint       = NULL;
14153     definedConstraintTwo    = NULL;
14154     definedConstraintPruned       = NULL;
14155     definedConstraintTwoPruned    = NULL;
14156     constraintNames         = NULL;
14157     nodeCalibration         = NULL;
14158     tempActiveConstraints   = NULL;                      /* holds temp info on active constraints         */
14159     outGroupNum             = 0;                         /* default outgroup                              */
14160     numTaxaSets             = 0;                         /* holds number of taxa sets                     */
14161 }
14162
14163
14164 /* SetPartition: Set model partition */
14165 int SetPartition (int part)
14166 {
14167     int     i, j;
14168     
14169     /* Free space for modelParams and modelSettings */
14170     if (memAllocs[ALLOC_MODEL] == YES)
14171         {
14172         for (i=0; i<numCurrentDivisions; i++)
14173           free (modelParams[i].activeConstraints);
14174         free (modelParams);
14175         free (modelSettings);
14176         modelParams = NULL;
14177         modelSettings = NULL;
14178         memAllocs[ALLOC_MODEL] = NO;
14179         }
14180
14181     /* Set model partition */
14182     partitionNum = part;
14183     numCurrentDivisions = 0;
14184
14185     /* Set numCurrentDivisions to maximum division a character belongs to in partition part */
14186     for (i=0; i<numChar; i++)
14187         {
14188         j = partitionId[i][part];
14189         if (j > numCurrentDivisions)
14190             numCurrentDivisions = j;
14191         }
14192
14193     /* Allocate space for partition models */
14194     modelParams = (Model *) SafeCalloc (numCurrentDivisions, sizeof (Model));
14195     modelSettings = (ModelInfo *) SafeCalloc (numCurrentDivisions, sizeof (ModelInfo));
14196     if (!modelParams || !modelSettings)
14197         {
14198         MrBayesPrint ("%s   Could not allocate modelParams or modelSettings\n", spacer);
14199         if (modelParams)
14200             free (modelParams);
14201         if (modelSettings)
14202             free (modelSettings);
14203         return (ERROR);
14204         }
14205     memAllocs[ALLOC_MODEL] = YES;
14206
14207     numVars = (int *) SafeRealloc ((void *) numVars, 3 * (size_t)numCurrentDivisions * sizeof(int));
14208     tempLinkUnlinkVec = numVars + numCurrentDivisions;
14209     activeParts       = numVars + 2*numCurrentDivisions;
14210
14211     tempNum = (MrBFlt *) SafeRealloc ((void *) tempNum, 6 * sizeof(MrBFlt));
14212
14213     activeParams[0] = (int *) SafeRealloc ((void *) (activeParams[0]), (size_t)NUM_LINKED * (size_t)numCurrentDivisions * sizeof(int));
14214     for (i=1; i<NUM_LINKED; i++)
14215         activeParams[i] = activeParams[0] + i*numCurrentDivisions;
14216  
14217     linkTable[0] = (int *) SafeRealloc ((void *) (linkTable[0]), 3 * (size_t)NUM_LINKED * (size_t)numCurrentDivisions * sizeof(int));
14218     tempLinkUnlink[0] = linkTable[0] + NUM_LINKED*numCurrentDivisions;
14219     for (i=1; i<NUM_LINKED; i++)
14220         {
14221         linkTable[i]      = linkTable[0] + i*numCurrentDivisions;
14222         tempLinkUnlink[i] = tempLinkUnlink[0] + i*numCurrentDivisions;
14223         }
14224
14225     return (NO_ERROR);
14226 }
14227
14228
14229 /* SetSpeciespartition: Set speciespartition */
14230 int SetSpeciespartition (int part)
14231 {
14232     int     i, j;
14233     
14234     /* Set model partition */
14235     speciespartitionNum = part;
14236     numSpecies = 0;
14237
14238     /* Set numSpecies to maximum species a taxon belongs to in partition part */
14239     for (i=0; i<numTaxa; i++)
14240         {
14241         j = speciespartitionId[i][part];
14242         if (j > numSpecies)
14243             numSpecies = j;
14244         }
14245
14246     return (NO_ERROR);
14247 }
14248
14249
14250 int SetTaxaFromTranslateTable (void)
14251 {
14252     int     i;
14253
14254     if (numTaxa != 0)
14255         return ERROR;
14256
14257     for (i=0; i<numTranslates; i++)
14258         {
14259         if (strlen(transFrom[i])>99)
14260             {
14261             MrBayesPrint ("%s   Taxon name %s is too long. Maximun 99 characters is allowed.\n", spacer, transFrom[i]);
14262             return (ERROR);
14263             }
14264         AddString(&taxaNames, numTaxa, transFrom[i]);
14265         numTaxa++;
14266         }
14267     
14268     return NO_ERROR;
14269 }
14270
14271
14272 void SetUpParms (void)
14273 {
14274     ParmInfoPtr p = paramTable;
14275
14276     PARAM   (0, "NEXUS",          DoNexusParm,       "NEXUS|\0");
14277     PARAM   (1, "Data",           DoBeginParm,       "\0");
14278     PARAM   (2, "Mrbayes",        DoBeginParm,       "\0");
14279     PARAM   (3, "Trees",          DoBeginParm,       "\0");
14280     PARAM   (4, "Ntax",           DoDimensionsParm,  "\0");
14281     PARAM   (5, "Nchar",          DoDimensionsParm,  "\0");
14282     PARAM   (6, "Interleave",     DoFormatParm,      "Yes|No|\0");
14283     PARAM   (7, "Datatype",       DoFormatParm,      "Dna|Rna|Protein|Restriction|Standard|Continuous|Mixed|\0");
14284     PARAM   (8, "Gap",            DoFormatParm,      "\0");
14285     PARAM   (9, "Missing",        DoFormatParm,      "\0");
14286     PARAM  (10, "Matchchar",      DoFormatParm,      "\0");
14287     PARAM  (11, "MatrixInfo",     DoMatrixParm,      "\0");
14288     PARAM  (12, "Filename",       DoExecuteParm,     "\0");
14289     PARAM  (13, "Autoclose",      DoSetParm,         "Yes|No|\0");
14290     PARAM  (14, "Partition",      DoSetParm,         "\0");
14291     PARAM  (15, "Xxxxxxxxxx",     DoCharsetParm,     "\0");
14292     PARAM  (16, "Xxxxxxxxxx",     DoPartitionParm,   "\0");
14293     PARAM  (17, "Seed",           DoMcmcParm,        "\0");
14294     PARAM  (18, "Ngen",           DoMcmcParm,        "\0");
14295     PARAM  (19, "Samplefreq",     DoMcmcParm,        "\0");
14296     PARAM  (20, "Printfreq",      DoMcmcParm,        "\0");
14297     PARAM  (21, "Nchains",        DoMcmcParm,        "\0");
14298     PARAM  (22, "Temp",           DoMcmcParm,        "\0");
14299     PARAM  (23, "Filename",       DoMcmcParm,        "\0");
14300     PARAM  (24, "Burnin",         DoMcmcParm,        "\0");
14301     PARAM  (25, "Starttree",      DoMcmcParm,        "Random|Current|User|Parsimony|NJ|\0");
14302     PARAM  (26, "Nperts",         DoMcmcParm,        "\0");
14303     PARAM  (27, "Savebrlens",     DoMcmcParm,        "Yes|No|\0");
14304     PARAM  (28, "Nucmodel",       DoLsetParm,        "4by4|Doublet|Codon|Protein|\0");
14305     PARAM  (29, "Nst",            DoLsetParm,        "1|2|6|Mixed|\0");
14306     PARAM  (30, "Aamodel",        DoLsetParm,        "Poisson|Equalin|Jones|Dayhoff|Mtrev|Mtmam|Wag|Rtrev|Cprev|Vt|Blosum|Blossum|LG|\0");
14307     PARAM  (31, "Parsmodel",      DoLsetParm,        "Yes|No|\0");
14308     PARAM  (32, "Omegavar",       DoLsetParm,        "Equal|Ny98|M3|M10|\0");
14309     PARAM  (33, "Code",           DoLsetParm,        "Universal|Vertmt|Invermt|Mycoplasma|Yeast|Ciliate|Echinoderm|Euplotid|Metmt|\0");
14310     PARAM  (34, "Coding",         DoLsetParm,        "All|Variable|Informative|Nosingletons|Noabsencesites|Nopresencesites|Nosingletonpresence|Nosingletonabsence|\0");
14311     PARAM  (35, "Seqerror",       DoPrsetParm,       "\0");
14312     PARAM  (36, "Tratiopr",       DoPrsetParm,       "Beta|Fixed|\0");
14313     PARAM  (37, "Revmatpr",       DoPrsetParm,       "Dirichlet|Fixed|\0");
14314     PARAM  (38, "Omegapr",        DoPrsetParm,       "Dirichlet|Fixed|\0");
14315     PARAM  (39, "Statefreqpr",    DoPrsetParm,       "Dirichlet|Fixed|\0");
14316     PARAM  (40, "Ngammacat",      DoLsetParm,        "\0");
14317     PARAM  (41, "Shapepr",        DoPrsetParm,       "Uniform|Exponential|Fixed|\0");
14318     PARAM  (42, "Ratecorrpr",     DoPrsetParm,       "Uniform|Fixed|\0");
14319     PARAM  (43, "Pinvarpr",       DoPrsetParm,       "Uniform|Fixed|\0");
14320     PARAM  (44, "Covswitchpr",    DoPrsetParm,       "Uniform|Exponential|Fixed|\0");
14321     PARAM  (45, "Xxxxxxxxxx",     DoExcludeParm,     "\0");
14322     PARAM  (46, "Xxxxxxxxxx",     DoIncludeParm,     "\0");
14323     PARAM  (47, "Xxxxxxxxxx",     DoDeleteParm,      "\0");
14324     PARAM  (48, "Xxxxxxxxxx",     DoRestoreParm,     "\0");
14325     PARAM  (49, "Xxxxxxxxxx",     DoTaxasetParm,     "\0");
14326     PARAM  (50, "Xxxxxxxxxx",     DoHelpParm,        "\0");
14327     PARAM  (51, "Applyto",        DoLsetParm,        "\0");
14328     PARAM  (52, "Rates",          DoLsetParm,        "Equal|Gamma|LNorm|Propinv|Invgamma|Adgamma|\0");
14329     PARAM  (53, "Covarion",       DoLsetParm,        "Yes|No|\0");
14330     PARAM  (54, "Applyto",        DoPrsetParm,       "\0");
14331     PARAM  (55, "Tratio",         DoLinkParm,        "\0");
14332     PARAM  (56, "Revmat",         DoLinkParm,        "\0");
14333     PARAM  (57, "Omega",          DoLinkParm,        "\0");
14334     PARAM  (58, "Statefreq",      DoLinkParm,        "\0");
14335     PARAM  (59, "Shape",          DoLinkParm,        "\0");
14336     PARAM  (60, "Pinvar",         DoLinkParm,        "\0");
14337     PARAM  (61, "Correlation",    DoLinkParm,        "\0");
14338     PARAM  (62, "Ratemultiplier", DoLinkParm,        "\0");
14339     PARAM  (63, "Switchrates",    DoLinkParm,        "\0");
14340     PARAM  (64, "Symdirihyperpr", DoPrsetParm,       "Uniform|Exponential|Fixed|\0");
14341     PARAM  (65, "Xxxxxxxxxx",     DoCtypeParm,       "\0");
14342     PARAM  (66, "Xxxxxxxxxx",     DoConstraintParm,  "\0");
14343     PARAM  (67, "Topologypr",     DoPrsetParm,       "Uniform|Constraints|Fixed|Speciestree|\0");
14344     PARAM  (68, "Brlenspr",       DoPrsetParm,       "Unconstrained|Clock|Relaxedclock|Fixed|\0");
14345     PARAM  (69, "Speciationpr",   DoPrsetParm,       "Uniform|Exponential|Fixed|\0");
14346     PARAM  (70, "Extinctionpr",   DoPrsetParm,       "Beta|Fixed|\0");
14347     PARAM  (71, "Popsizepr",      DoPrsetParm,       "Lognormal|Uniform|Gamma|Normal|Fixed|\0");
14348     PARAM  (72, "Topology",       DoLinkParm,        "\0");
14349     PARAM  (73, "Brlens",         DoLinkParm,        "\0");
14350     PARAM  (74, "Speciationrate", DoLinkParm,        "\0");
14351     PARAM  (75, "Extinctionrate", DoLinkParm,        "\0");
14352     PARAM  (76, "Popsize",        DoLinkParm,        "\0");
14353     PARAM  (77, "Ratepr",         DoPrsetParm,       "Variable|Dirichlet|Fixed|\0");
14354     PARAM  (78, "Xxxxxxxxxx",     DoOutgroupParm,    "\0");
14355     PARAM  (79, "Xxxxxxxxxx",     DoTreeParm,        "\0");
14356     PARAM  (80, "Filename",       DoSumtParm,        "\0");
14357     PARAM  (81, "Burnin",         DoSumtParm,        "\0");
14358     PARAM  (82, "Contype",        DoSumtParm,        "Halfcompat|Allcompat|\0");
14359     PARAM  (83, "Xxxxxxxxxx",     DoTranslateParm,   "\0");
14360     PARAM  (84, "Swapfreq",       DoMcmcParm,        "\0");
14361     PARAM  (85, "Start",          DoLogParm,         "\0");
14362     PARAM  (86, "Stop",           DoLogParm,         "\0");
14363     PARAM  (87, "Filename",       DoLogParm,         "\0");
14364     PARAM  (88, "Append",         DoLogParm,         "\0");
14365     PARAM  (89, "Replace",        DoLogParm,         "\0");
14366     PARAM  (90, "Nbetacat",       DoLsetParm,        "\0");
14367     PARAM  (91, "Augment",        DoLsetParm,        "Yes|No|\0");
14368     PARAM  (92, "Xxxxxxxxxx",     DoPairsParm,       "\0");
14369     PARAM  (93, "Xxxxxxxxxx",     DoBreaksParm,      "\0");
14370     PARAM  (94, "Nowarnings",     DoSetParm,         "Yes|No|\0");
14371     PARAM  (95, "Showtreeprobs",  DoSumtParm,        "Yes|No|\0");
14372     PARAM  (96, "Filename",       DoSumpParm,        "\0");
14373     PARAM  (97, "Burnin",         DoSumpParm,        "\0");
14374     PARAM  (98, "Reweight",       DoMcmcParm,        "\0");
14375     PARAM  (99, "Noop",           DoMcmcParm,        "\0");
14376     PARAM (100, "Ny98omega1pr",   DoPrsetParm,       "Beta|Fixed|\0");
14377     PARAM (101, "Ny98omega3pr",   DoPrsetParm,       "Uniform|Exponential|Fixed|\0");
14378     PARAM (102, "Codoncatfreqs",  DoPrsetParm,       "Dirichlet|Fixed|\0");
14379     PARAM (103, "Sampleprob",     DoPrsetParm,       "\0");
14380     PARAM (104, "Aamodelpr",      DoPrsetParm,       "Fixed|Mixed|\0");
14381     PARAM (105, "Aamodel",        DoLinkParm,        "\0");
14382     PARAM (106, "Filename",       DoPlotParm,        "\0");
14383     PARAM (107, "Parameter",      DoPlotParm,        "\0");
14384     PARAM (108, "Match",          DoPlotParm,        "Perfect|Consistentwith|All|\0");
14385     PARAM (109, "Burnin",         DoPlotParm,        "\0");
14386     PARAM (110, "Brownscalepr",   DoPrsetParm,       "Uniform|Gamma|Gammamean|Fixed|\0");
14387     PARAM (111, "Browncorrpr",    DoPrsetParm,       "Uniform|Fixed|\0");
14388     PARAM (112, "Pbf",            DoMcmcParm,        "Yes|No|\0");
14389     PARAM (113, "Pbfinitburnin",  DoMcmcParm,        "\0");
14390     PARAM (114, "Pbfsamplefreq",  DoMcmcParm,        "\0");
14391     PARAM (115, "Pbfsampletime",  DoMcmcParm,        "\0");
14392     PARAM (116, "Pbfsampleburnin",DoMcmcParm,        "\0");
14393     PARAM (117, "Growthpr",       DoPrsetParm,       "Uniform|Exponential|Fixed|Normal|\0");
14394     PARAM (118, "Growthrate",     DoLinkParm,        "\0");
14395     PARAM (119, "Xxxxxxxxxx",     DoCalibrateParm,   "Unconstrained|Fixed|Uniform|Offsetexponential|Truncatednormal|Lognormal|Offsetlognormal|Gamma|Offsetgamma|\0");
14396     PARAM (120, "Calwaitpr",      DoPrsetParm,       "Exponential|Fixed|\0");     /* not used but leave it in to not destroy mapping to commands */
14397     PARAM (121, "M3omegapr",      DoPrsetParm,       "Exponential|Fixed|\0");
14398     PARAM (122, "Applyto",        DoReportParm,      "\0");
14399     PARAM (123, "Tratio",         DoReportParm,      "Dirichlet|Ratio|\0");
14400     PARAM (124, "Revmat",         DoReportParm,      "Dirichlet|Ratio|\0");
14401     PARAM (125, "Ratemult",       DoReportParm,      "Dirichlet|Scaled|Ratio|\0");
14402     PARAM (126, "Filename",       DoManualParm,      "\0");
14403     PARAM (127, "Filename1",      DoCompareTreeParm, "\0");
14404     PARAM (128, "Filename2",      DoCompareTreeParm, "\0");
14405     PARAM (129, "Outputname",     DoCompareTreeParm, "\0");
14406     PARAM (130, "Burnin",         DoCompareTreeParm, "\0");
14407     PARAM (131, "Ploidy",         DoLsetParm,        "Haploid|Diploid|Zlinked|\0");
14408     PARAM (132, "Swapadjacent",   DoMcmcParm,        "Yes|No|\0");
14409     PARAM (133, "Treeagepr",      DoPrsetParm,       "Fixed|Uniform|Offsetexponential|Truncatednormal|Lognormal|Offsetlognormal|Gamma|Offsetgamma|\0");
14410     PARAM (134, "Ancstates",      DoReportParm,      "Yes|No|\0");
14411     PARAM (135, "Siterates",      DoReportParm,      "Yes|No|\0");
14412     PARAM (136, "Possel",         DoReportParm,      "Yes|No|\0");
14413     PARAM (137, "Plot",           DoSumpParm,        "Yes|No|\0");
14414     PARAM (138, "Table",          DoSumpParm,        "Yes|No|\0");
14415     PARAM (139, "Minprob",        DoSumpParm,        "\0");
14416     PARAM (140, "Printtofile",    DoSumpParm,        "Yes|No|\0");
14417     PARAM (141, "Outputname",     DoSumpParm,        "\0");
14418     PARAM (142, "Redirect",       DoMcmcParm,        "Yes|No|\0");
14419     PARAM (143, "Swapseed",       DoMcmcParm,        "\0");
14420     PARAM (144, "Runidseed",      DoMcmcParm,        "\0");
14421     PARAM (145, "Quitonerror",    DoSetParm,         "Yes|No|\0");
14422     PARAM (146, "Printbrlens",    DoSumtParm,        "Yes|No|\0");
14423     PARAM (147, "Brlensgeq",      DoSumtParm,        "\0");
14424     PARAM (148, "Minpartfreq",    DoMcmcParm,        "\0");
14425     PARAM (149, "Allchains",      DoMcmcParm,        "Yes|No|\0");
14426     PARAM (150, "Mcmcdiagn",      DoMcmcParm,        "Yes|No|\0");
14427     PARAM (151, "Diagnfreq",      DoMcmcParm,        "\0");
14428     PARAM (152, "Nruns",          DoMcmcParm,        "\0");
14429     PARAM (153, "Stoprule",       DoMcmcParm,        "Yes|No|\0");
14430     PARAM (154, "Stopval",        DoMcmcParm,        "\0");
14431     PARAM (155, "Relburnin",      DoMcmcParm,        "Yes|No|\0");
14432     PARAM (156, "Burninfrac",     DoMcmcParm,        "\0");
14433     PARAM (157, "Allcomps",       DoMcmcParm,        "Yes|No|\0");
14434     PARAM (158, "Printall",       DoMcmcParm,        "Yes|No|\0");
14435     PARAM (159, "Printmax",       DoMcmcParm,        "\0");
14436     PARAM (160, "Data",           DoMcmcParm,        "Yes|No|\0");
14437     PARAM (161, "Nruns",          DoSumpParm,        "\0");
14438     PARAM (162, "Allruns",        DoSumpParm,        "Yes|No|\0");
14439     PARAM (163, "Nruns",          DoSumtParm,        "\0");
14440     PARAM (164, "Ntrees",         DoSumtParm,        "\0");
14441     PARAM (165, "Calctreeprobs",  DoSumtParm,        "Yes|No|\0");
14442     PARAM (166, "Ordertaxa",      DoMcmcParm,        "Yes|No|\0");
14443     PARAM (167, "Ordertaxa",      DoSumtParm,        "Yes|No|\0");
14444     PARAM (168, "Aarevmatpr",     DoPrsetParm,       "Dirichlet|Fixed|\0");
14445     PARAM (169, "Nswaps",         DoMcmcParm,        "\0");
14446     PARAM (170, "Autoreplace",    DoSetParm,         "Yes|No|\0");
14447     PARAM (171, "Npthreads",      DoSetParm,         "\0");
14448     PARAM (172, "Cppratepr",      DoPrsetParm,       "Fixed|Exponential|\0");
14449     PARAM (173, "Cppmultdevpr",   DoPrsetParm,       "Fixed|\0");
14450     PARAM (174, "TK02varpr",      DoPrsetParm,       "Fixed|Exponential|Uniform|\0");
14451     PARAM (175, "Pfile",          DoSumtParm,        "\0");
14452     PARAM (176, "Pfile",          DoSumtParm,        "\0");
14453     PARAM (177, "Autocomplete",   DoSumtParm,        "Yes|No|\0");
14454     PARAM (178, "Autocomplete",   DoSumpParm,        "Yes|No|\0");
14455     PARAM (179, "Userlevel",      DoSetParm,         "Standard|Developer|\0");
14456     PARAM (180, "Allavailable",   DoShowmovesParm,   "Yes|No|\0");
14457     PARAM (181, "Seed",           DoSetParm,         "\0");
14458     PARAM (182, "Swapseed",       DoSetParm,         "\0");
14459     PARAM (183, "Clockratepr",    DoPrsetParm,       "Fixed|Normal|Lognormal|Exponential|Gamma|\0");
14460     PARAM (184, "Nodeagepr",      DoPrsetParm,       "Unconstrained|Calibrated|\0");
14461     PARAM (185, "Clockvarpr",     DoPrsetParm,       "Strict|Cpp|TK02|Igr|Bm|Ibr|Mixed|\0");
14462     PARAM (186, "Xxxxxxxxxx",     DoPropsetParm,     "\0");
14463     PARAM (187, "Xxxxxxxxxx",     DoStartvalsParm,   "\0");
14464     PARAM (188, "Usegibbs",       DoLsetParm,        "Yes|No|\0");
14465     PARAM (189, "Gibbsfreq",      DoLsetParm,        "\0");
14466     PARAM (190, "Checkpoint",     DoMcmcParm,        "Yes|No|\0");
14467     PARAM (191, "Checkfreq",      DoMcmcParm,        "\0");
14468     PARAM (192, "Tree",           DoReportParm,      "Topology|Brlens|\0");
14469     PARAM (193, "Cpprate",        DoLinkParm,        "\0");
14470     PARAM (194, "Cppmultdev",     DoLinkParm,        "\0");
14471     PARAM (195, "Cppevents",      DoLinkParm,        "\0");
14472     PARAM (196, "TK02var",        DoLinkParm,        "\0");
14473     PARAM (197, "TK02branchrates",DoLinkParm,        "\0");
14474     PARAM (198, "Savetrees",      DoMcmcParm,        "Yes|No|\0");
14475     PARAM (199, "Diagnstat",      DoMcmcParm,        "Avgstddev|Maxstddev|\0");
14476     PARAM (200, "Startparams",    DoMcmcParm,        "Reset|Current|\0");
14477     PARAM (201, "Characters",     DoBeginParm,       "\0");
14478     PARAM (202, "Startingtrees",  DoMcmcParm,        "\0");
14479     PARAM (203, "Xxxxxxxxxx",     DoUserTreeParm,    "\0");
14480     PARAM (204, "Outputname",     DoSumtParm,        "\0");
14481     PARAM (205, "Table",          DoSumtParm,        "Yes|No|\0");
14482     PARAM (206, "Summary",        DoSumtParm,        "Yes|No|\0");
14483     PARAM (207, "Consensus",      DoSumtParm,        "Yes|No|\0");
14484     PARAM (208, "Minpartfreq",    DoSumtParm,        "\0");
14485     PARAM (209, "Relburnin",      DoSumtParm,        "Yes|No|\0");
14486     PARAM (210, "Burninfrac",     DoSumtParm,        "\0");
14487     PARAM (211, "Relburnin",      DoSumpParm,        "Yes|No|\0");
14488     PARAM (212, "Burninfrac",     DoSumpParm,        "\0");
14489     PARAM (213, "Append",         DoMcmcParm,        "Yes|No|\0");
14490     PARAM (214, "Autotune",       DoMcmcParm,        "Yes|No|\0");
14491     PARAM (215, "Tunefreq",       DoMcmcParm,        "\0");
14492     PARAM (216, "Scientific",     DoSetParm,         "Yes|No|\0");
14493     PARAM (217, "Siteomega",      DoReportParm,      "Yes|No|\0");
14494     PARAM (218, "Igrvarpr",       DoPrsetParm,       "Fixed|Exponential|Uniform|\0");
14495     PARAM (219, "Symbols",        DoFormatParm,      "\0");
14496     PARAM (220, "Equate",         DoFormatParm,      "\0");
14497     PARAM (221, "Relburnin",      DoCompareTreeParm, "Yes|No|\0");
14498     PARAM (222, "Burninfrac",     DoCompareTreeParm, "\0");
14499     PARAM (223, "Minpartfreq",    DoCompareTreeParm, "\0");
14500     PARAM (224, "Relburnin",      DoPlotParm,        "Yes|No|\0");
14501     PARAM (225, "Burninfrac",     DoPlotParm,        "\0");
14502     PARAM (226, "Taxa",           DoBeginParm,       "\0");
14503     PARAM (227, "Xxxxxxxxxx",     DoBeginParm,       "\0");
14504     PARAM (228, "Xxxxxxxxxx",     DoTaxlabelsParm,   "\0");
14505     PARAM (229, "Dir",            DoSetParm,         "\0");
14506     PARAM (230, "Conformat",      DoSumtParm,        "Figtree|Simple|\0");
14507     PARAM (231, "Hpd",            DoSumpParm,        "Yes|No|\0");
14508     PARAM (232, "Hpd",            DoSumtParm,        "Yes|No|\0");
14509     PARAM (233, "Usebeagle",      DoSetParm,         "Yes|No|\0");
14510     PARAM (234, "Beagledevice",   DoSetParm,         "Cpu|Gpu|\0");
14511     PARAM (235, "Beagleprecision",DoSetParm,         "Single|Double|\0");
14512     PARAM (236, "Beaglesse",      DoSetParm,         "Yes|No|\0");
14513     PARAM (237, "Beagleopenmp",   DoSetParm,         "Yes|No|\0");
14514     PARAM (238, "Beaglethreads",  DoSetParm,         "Yes|No|\0");
14515     PARAM (239, "Beaglescaling",  DoSetParm,         "Always|Dynamic|\0");
14516     PARAM (240, "Beaglefreq",     DoSetParm,         "\0");
14517     PARAM (241, "Popvarpr",       DoPrsetParm,       "Equal|Variable|\0");
14518     PARAM (242, "Igrvar",         DoLinkParm,        "\0");
14519     PARAM (243, "Igrbranchrates", DoLinkParm,        "\0");
14520     PARAM (244, "Xxxxxxxxxx",     DoSpeciespartitionParm,   "\0");
14521     PARAM (245, "Speciespartition",  DoSetParm,      "\0");
14522     PARAM (246, "Revratepr",      DoPrsetParm,       "Symdir|\0");
14523     PARAM (247, "Samplestrat",    DoPrsetParm,       "Random|Diversity|Cluster|FossilTip|\0");
14524     PARAM (248, "Burninss",       DoSsParm,          "\0");
14525     PARAM (249, "Nsteps",         DoSsParm,          "\0");
14526     PARAM (250, "Alpha",          DoSsParm,          "\0");
14527     PARAM (251, "Bmvarpr",        DoPrsetParm,       "Fixed|Exponential|Uniform|\0");
14528     PARAM (252, "Bmvar",          DoLinkParm,        "\0");
14529     PARAM (253, "Bmbranchrates",  DoLinkParm,        "\0");
14530     PARAM (254, "Ibrvarpr",       DoPrsetParm,       "Fixed|Exponential|Uniform|\0");
14531     PARAM (255, "Ibrvar",         DoLinkParm,        "\0");
14532     PARAM (256, "Ibrbranchlens",  DoLinkParm,        "\0");
14533     PARAM (257, "FromPrior",      DoSsParm,          "Yes|No|\0");
14534     PARAM (258, "Filename",       DoSumSsParm,       "\0");
14535     PARAM (259, "Burnin",         DoSumSsParm,       "\0");
14536     PARAM (260, "Nruns",          DoSumSsParm,       "\0");
14537     PARAM (261, "Allruns",        DoSumSsParm,       "Yes|No|\0");
14538     PARAM (262, "Askmore",        DoSumSsParm,       "Yes|No|\0");
14539     PARAM (263, "Relburnin",      DoSumSsParm,       "Yes|No|\0");
14540     PARAM (264, "Burninfrac",     DoSumSsParm,       "\0");
14541     PARAM (265, "Discardfrac",    DoSumSsParm,       "\0");
14542     PARAM (266, "Smoothing",      DoSumSsParm,       "\0");
14543     PARAM (267, "Steptoplot",     DoSumSsParm,       "\0");
14544     PARAM (268, "Precision",      DoSetParm,         "\0");
14545     PARAM (269, "Fossilizationpr",   DoPrsetParm,    "Beta|Fixed|\0");
14546     PARAM (270, "Fossilizationrate", DoLinkParm,     "\0");
14547     PARAM (271, "Generatepr",     DoPrsetParm,       "Variable|Fixed|\0");
14548     PARAM (272, "Mixedvarpr",     DoPrsetParm,       "Fixed|Exponential|Uniform|\0");
14549     PARAM (273, "Mixedvar",       DoLinkParm,        "\0");
14550     PARAM (274, "Mixedbrchrates", DoLinkParm,        "\0");
14551     PARAM (275, "Beagleresource", DoSetParm,         "\0");
14552
14553     /* NOTE: If a change is made to the parameter table, make certain you change
14554             NUMPARAMS (now 276; one more than last index) at the top of this file. */
14555     /* CmdType commands[] */
14556 }
14557
14558
14559 void ShowNodes (TreeNode *p, int indent, int isThisTreeRooted)
14560 {
14561     if (p != NULL)
14562         {
14563         printf ("   ");
14564         if (p->left == NULL && p->right == NULL && p->anc != NULL)
14565             {
14566             printf ("%*cN %d (l=%d r=%d a=%d) %1.15lf (%s) scalerNode=%d isDated=%d ",
14567             indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc), p->length, p->label, p->scalerNode, p->isDated);
14568             }
14569         else if (p->left != NULL && p->right == NULL && p->anc == NULL)
14570             {
14571             if (isThisTreeRooted == NO)
14572                 {
14573                 if (p->label[0] == '\0' || p->label[0] == '\n' || p->label[0] == ' ')
14574                     printf ("%*cN %d (l=%d r=%d a=%d) (---) scalerNode=%d ",
14575                     indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc), p->scalerNode);
14576                 else
14577                     printf ("%*cN %d (l=%d r=%d a=%d) (%s) scalerNode=%d ",
14578                     indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc), p->label, p->scalerNode);
14579                 }
14580             else
14581                 {
14582                 printf ("%*cN %d (l=%d r=%d a=%d) X.XXXXXX scalerNode=%d ",
14583                 indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc), p->scalerNode);
14584                 }
14585             }
14586         else
14587             {
14588             if (p->anc != NULL)
14589                 {
14590                 if (p->anc->anc == NULL && isThisTreeRooted == YES)
14591                     printf ("%*cN %d (l=%d r=%d a=%d) X.XXXXXX scalerNode=%d ",
14592                     indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc), p->scalerNode);
14593                 else    
14594                     printf ("%*cN %d (l=%d r=%d a=%d) %1.15lf scalerNode=%d ",
14595                     indent, ' ', Dex(p), Dex(p->left), Dex(p->right), Dex(p->anc), p->length, p->scalerNode);
14596                 }
14597             }
14598         if (isThisTreeRooted == YES)
14599             printf ("depth=%1.15lf\n", p->nodeDepth);
14600         else
14601             printf ("\n");
14602         ShowNodes (p->left,  indent + 2, isThisTreeRooted);
14603         ShowNodes (p->right, indent + 2, isThisTreeRooted);
14604         }
14605 }
14606
14607
14608 int StandID (char nuc)
14609 {
14610     char        n;
14611     
14612     /* Note that if you change how many states are recognized, you need 
14613        to look at IsMissing */
14614     n = nuc;
14615
14616     if (n == '0')
14617         {
14618         return 1;
14619         }
14620     else if (n == '1')
14621         {
14622         return 2;
14623         }
14624     else if (n == '2')
14625         {
14626         return 4;
14627         }
14628     else if (n == '3')
14629         {
14630         return 8;
14631         }
14632     else if (n == '4')
14633         {
14634         return 16;
14635         }
14636     else if (n == '5')
14637         {
14638         return 32;
14639         }
14640     else if (n == '6')
14641         {
14642         return 64;
14643         }
14644     else if (n == '7')
14645         {
14646         return 128;
14647         }
14648     else if (n == '8')
14649         {
14650         return 256;
14651         }
14652     else if (n == '9')
14653         {
14654         return 512;
14655         }
14656     else if (n == missingId)
14657         {
14658         return MISSING;
14659         }
14660     else if (n == gapId)
14661         {
14662         return GAP;
14663         }
14664     else
14665         return -1;
14666 }
14667
14668
14669 void State_CODON (char *state, int code, int division)
14670 {
14671     state[0] = StateCode_NUC4(modelParams[division].codonNucs[code][0]);
14672     state[1] = StateCode_NUC4(modelParams[division].codonNucs[code][1]);
14673     state[2] = StateCode_NUC4(modelParams[division].codonNucs[code][2]);
14674     state[3] = '\0';
14675 }
14676
14677
14678 void State_DOUBLET (char *state, int code)
14679 {
14680     state[0] = code/4 + 'A';
14681     state[1] = code%4 + 'A';
14682     state[2] = '\0';
14683 }
14684
14685
14686 int StateCode_AA (int n)
14687 {
14688     if (n == 0)
14689         return 'A';      /* Ala */
14690     else if (n == 1)
14691         return 'R';      /* Arg */
14692     else if (n == 2)
14693         return 'N';      /* Asn */
14694     else if (n == 3)
14695         return 'D';      /* Asp */
14696     else if (n == 4)
14697         return 'C';      /* Cys */
14698     else if (n == 5)
14699         return 'Q';      /* Gln */
14700     else if (n == 6)
14701         return 'E';      /* Glu */
14702     else if (n == 7)
14703         return 'G';      /* Gly */
14704     else if (n == 8)
14705         return 'H';      /* His */
14706     else if (n == 9)
14707         return 'I';      /* Ile */
14708     else if (n == 10)
14709         return 'L';      /* Leu */
14710     else if (n == 11)
14711         return 'K';      /* Lys */
14712     else if (n == 12)
14713         return 'M';      /* Met */
14714     else if (n == 13)
14715         return 'F';      /* Phe */
14716     else if (n == 14)
14717         return 'P';      /* Pro */
14718     else if (n == 15)
14719         return 'S';      /* Ser */
14720     else if (n == 16)
14721         return 'T';      /* Thr */
14722     else if (n == 17)
14723         return 'W';      /* Trp */
14724     else if (n == 18)
14725         return 'Y';      /* Tyr */
14726     else if (n == 19)
14727         return 'V';      /* Val */
14728     else
14729         return '?';
14730 }
14731
14732
14733 int StateCode_NUC4 (int n)
14734 {
14735     if (n == 0)
14736         return 'A';
14737     else if (n == 1)
14738         return 'C';
14739     else if (n == 2)
14740         return 'G';
14741     else if (n == 3)
14742         return 'T';
14743     else return '?';
14744 }
14745
14746
14747 int StateCode_Std (int n)
14748 {
14749     if (n <= 9 && n >= 0)
14750         return '0' + n;
14751     else return '?';
14752 }
14753
14754
14755 void WhatVariableExp (BitsLong exp, char *st)
14756 {
14757     int         n;
14758     
14759     strcpy (st, "");
14760     n = 0;
14761     if (exp == 0)
14762         strcat(st, " nothing");
14763     else
14764         {
14765         if ((exp & Expecting(COMMAND)) == Expecting(COMMAND))
14766             {
14767             strcat(st, " command");
14768             n++;
14769             }
14770         if ((exp & Expecting(PARAMETER)) == Expecting(PARAMETER))
14771             {
14772             if (n > 0)
14773                 strcat(st, " or");
14774             strcat(st, " parameter");
14775             n++;
14776             }
14777         if ((exp & Expecting(EQUALSIGN)) == Expecting(EQUALSIGN))
14778             {
14779             if (n > 0)
14780                 strcat(st, " or");
14781             strcat(st, " =");
14782             n++;
14783             }
14784         if ((exp & Expecting(COLON)) == Expecting(COLON))
14785             {
14786             if (n > 0)
14787                 strcat(st, " or");
14788             strcat(st, " :");
14789             n++;
14790             }
14791         if ((exp & Expecting(SEMICOLON)) == Expecting(SEMICOLON))
14792             {
14793             if (n > 0)
14794                 strcat(st, " or");
14795             strcat(st, " ;");
14796             n++;
14797             }
14798         if ((exp & Expecting(COMMA)) == Expecting(COMMA))
14799             {
14800             if (n > 0)
14801                 strcat(st, " or");
14802             strcat(st, " ,");
14803             n++;
14804             }
14805         if ((exp & Expecting(POUNDSIGN)) == Expecting(POUNDSIGN))
14806             {
14807             if (n > 0)
14808                 strcat(st, " or");
14809             strcat(st, " #");
14810             n++;
14811             }
14812         if ((exp & Expecting(QUESTIONMARK)) == Expecting(QUESTIONMARK))
14813             {
14814             if (n > 0)
14815                 strcat(st, " or");
14816             strcat(st, " ?");
14817             n++;
14818             }
14819         if ((exp & Expecting(DASH)) == Expecting(DASH))
14820             {
14821             if (n > 0)
14822                 strcat(st, " or");
14823             strcat(st, " -");
14824             n++;
14825             }
14826         if ((exp & Expecting(LEFTPAR)) == Expecting(LEFTPAR))
14827             {
14828             if (n > 0)
14829                 strcat(st, " or");
14830             strcat(st, " (");
14831             n++;
14832             }
14833         if ((exp & Expecting(RIGHTPAR)) == Expecting(RIGHTPAR))
14834             {
14835             if (n > 0)
14836                 strcat(st, " or");
14837             strcat(st, " )");
14838             n++;
14839             }
14840         if ((exp & Expecting(LEFTCOMMENT)) == Expecting(LEFTCOMMENT))
14841             {
14842             if (n > 0)
14843                 strcat(st, " or");
14844             strcat(st, " [");
14845             n++;
14846             }
14847         if ((exp & Expecting(RIGHTCOMMENT)) == Expecting(RIGHTCOMMENT))
14848             {
14849             if (n > 0)
14850                 strcat(st, " or");
14851             strcat(st, " ]");
14852             n++;
14853             }
14854         if ((exp & Expecting(ALPHA)) == Expecting(ALPHA))
14855             {
14856             if (n > 0)
14857                 strcat(st, " or");
14858             strcat(st, " <name>");
14859             n++;
14860             }
14861         if ((exp & Expecting(NUMBER)) == Expecting(NUMBER))
14862             {
14863             if (n > 0)
14864                 strcat(st, " or");
14865             strcat(st, " <number>");
14866             n++;
14867             }
14868         if ((exp & Expecting(RETURNSYMBOL)) == Expecting(RETURNSYMBOL))
14869             {
14870             if (n > 0)
14871                 strcat(st, " or");
14872             strcat(st, " return");
14873             n++;
14874             }
14875         if ((exp & Expecting(ASTERISK)) == Expecting(ASTERISK))
14876             {
14877             if (n > 0)
14878                 strcat(st, " or");
14879             strcat(st, " *");
14880             n++;
14881             }
14882         if ((exp & Expecting(BACKSLASH)) == Expecting(BACKSLASH))
14883             {
14884             if (n > 0)
14885                 strcat(st, " or");
14886             strcat(st, " /");
14887             n++;
14888             }
14889         if ((exp & Expecting(BACKSLASH)) == Expecting(BACKSLASH))
14890             {
14891             if (n > 0)
14892                 strcat(st, " or");
14893             strcat(st, " \\");
14894             n++;
14895             }
14896         if ((exp & Expecting(EXCLAMATIONMARK)) == Expecting(EXCLAMATIONMARK))
14897             {
14898             if (n > 0)
14899                 strcat(st, " or");
14900             strcat(st, " !");
14901             n++;
14902             }
14903         if ((exp & Expecting(PERCENT)) == Expecting(PERCENT))
14904             {
14905             if (n > 0)
14906                 strcat(st, " or");
14907             strcat(st, " %");
14908             n++;
14909             }
14910         if ((exp & Expecting(LEFTCURL)) == Expecting(LEFTCURL))
14911             {
14912             if (n > 0)
14913                 strcat(st, " or");
14914             strcat(st, " {");
14915             n++;
14916             }
14917         if ((exp & Expecting(RIGHTCURL)) == Expecting(RIGHTCURL))
14918             {
14919             if (n > 0)
14920                 strcat(st, " or");
14921             strcat(st, " }");
14922             n++;
14923             }
14924         if ((exp & Expecting(WEIRD)) == Expecting(WEIRD))
14925             {
14926             if (n > 0)
14927                 strcat(st, " or");
14928             strcat(st, " <whatever>");
14929             n++;
14930             }
14931         if ((exp & Expecting(VERTICALBAR)) == Expecting(VERTICALBAR))
14932             {
14933             if (n > 0)
14934                 strcat(st, " or");
14935             strcat(st, " |");
14936             n++;
14937             }
14938         if ((exp & Expecting(UNKNOWN_TOKEN_TYPE)) == Expecting(UNKNOWN_TOKEN_TYPE))
14939             {
14940             if (n > 0)
14941                 strcat(st, " or");
14942             strcat(st, " no clue");
14943             n++;
14944             }
14945         }
14946 }
14947
14948
14949 char WhichAA (int x)
14950 {
14951     if (x == 1)
14952         return ('A');
14953     else if (x == 2)
14954         return ('R');
14955     else if (x == 4)
14956         return ('N');
14957     else if (x == 8)
14958         return ('D');
14959     else if (x == 16)
14960         return ('C');
14961     else if (x == 32)
14962         return ('Q');
14963     else if (x == 64)
14964         return ('E');
14965     else if (x == 128)
14966         return ('G');
14967     else if (x == 256)
14968         return ('H');
14969     else if (x == 512)
14970         return ('I');
14971     else if (x == 1024)
14972         return ('L');
14973     else if (x == 2048)
14974         return ('K');
14975     else if (x == 4096)
14976         return ('M');
14977     else if (x == 8192)
14978         return ('F');
14979     else if (x == 16384)
14980         return ('P');
14981     else if (x == 32768)
14982         return ('S');
14983     else if (x == 65536)
14984         return ('T');
14985     else if (x == 131072)
14986         return ('W');
14987     else if (x == 262144)
14988         return ('Y');
14989     else if (x == 524288)
14990         return ('V');
14991     else if (x > 0 && x < 524288)
14992         return ('*');
14993     else if (x == MISSING)
14994         return ('?');
14995     else if (x == GAP)
14996         return ('-');
14997     else 
14998         return (' ');
14999 }
15000
15001
15002 MrBFlt WhichCont (int x)
15003 {
15004     return ((MrBFlt)(x / 1000.0));
15005 }
15006
15007
15008 char WhichNuc (int x)
15009 {
15010     if (x == 1)
15011         return ('A');
15012     else if (x == 2)
15013         return ('C');
15014     else if (x == 3)
15015         return ('M');
15016     else if (x == 4)
15017         return ('G');
15018     else if (x == 5)
15019         return ('R');
15020     else if (x == 6)
15021         return ('S');
15022     else if (x == 7)
15023         return ('V');
15024     else if (x == 8)
15025         return ('T');
15026     else if (x == 9)
15027         return ('W');
15028     else if (x == 10)
15029         return ('Y');
15030     else if (x == 11)
15031         return ('H');
15032     else if (x == 12)
15033         return ('K');
15034     else if (x == 13)
15035         return ('D');
15036     else if (x == 14)
15037         return ('B');
15038     else if (x == 15)
15039         return ('N');
15040     else if (x == MISSING)
15041         return ('?');
15042     else if (x == GAP)
15043         return ('-');
15044     else 
15045         return (' ');
15046 }
15047
15048
15049 char WhichRes (int x)
15050 {
15051     if (x == 1)
15052         return ('0');
15053     else if (x == 2)
15054         return ('1');
15055     else if (x == 3)
15056         return ('*');
15057     else if (x == MISSING)
15058         return ('N');
15059     else if (x == GAP)
15060         return ('-');
15061     else 
15062         return (' ');
15063 }
15064
15065
15066 char WhichStand (int x)
15067 {
15068     if (x == 1)
15069         return ('0');
15070     else if (x == 2)
15071         return ('1');
15072     else if (x == 4)
15073         return ('2');
15074     else if (x == 8)
15075         return ('3');
15076     else if (x == 16)
15077         return ('4');
15078     else if (x == 32)
15079         return ('5');
15080     else if (x == 64)
15081         return ('6');
15082     else if (x == 128)
15083         return ('7');
15084     else if (x == 256)
15085         return ('8');
15086     else if (x == 512)
15087         return ('9');
15088     else if (x > 0 && x < 512)
15089         return ('*');
15090     else if (x == MISSING)
15091         return ('N');
15092     else if (x == GAP)
15093         return ('-');
15094     else 
15095         return (' ');
15096 }
15097