/* * MrBayes 3.1.2 * * copyright 2002-2005 * * John P. Huelsenbeck * Section of Ecology, Behavior and Evolution * Division of Biological Sciences * University of California, San Diego * La Jolla, CA 92093-0116 * * johnh@biomail.ucsd.edu * * Fredrik Ronquist * School of Computational Science * Florida State University * Tallahassee, FL 32306-4120 * * ronquist@csit.fsu.edu * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details (www.gnu.org). * */ #include #include #include #include #include #include #include "mb.h" #include "globals.h" #include "command.h" #include "bayes.h" #include "model.h" #include "mcmc.h" #include "plot.h" #include "sump.h" #include "sumt.h" #if defined(__MWERKS__) #include "SIOUX.h" #endif # define NUMCOMMANDS 53 /* Note: NUMCOMMANDS gives the total number */ /* of commands in the program */ #define NUMPARAMS 200 #define PARAM(i, s, f, l) p->string = s; \ p->fp = f; \ p->valueList = l; \ p++; #define HIDE 0 #define SHOW 1 #undef SHOW_TOKENS int AddToSet (int i, int j, int k, int id); int AllocMatrix (void); char ChangeCase (char c); int CharacterCode (char ch, int *charCode, int chType); int CharacterNumber (int charCode, int chType); int CheckInitialPartitions (void); int Dex (TreeNode *p); int DoAbout (void); int DoAcknowledgments (void); int DoBeginParm (char *parmName, char *tkn); int DoBreaks (void); int DoBreaksParm (char *parmName, char *tkn); int DoCalibrate (void); int DoCalibrateParm (char *parmName, char *tkn); int DoCharset (void); int DoCharsetParm (char *parmName, char *tkn); int DoCharStat (void); int DoCitations (void); int DoConstraints (void); int DoConstraintsParm (char *parmName, char *tkn); int DoCtype (void); int DoCtypeParm (char *parmName, char *tkn); int DoDelete (void); int DoDeleteParm (char *parmName, char *tkn); int DoDeroot (void); int DoDimensions (void); int DoDimensionsParm (char *parmName, char *tkn); int DoDisclaimer (void); int DoEndBlock (void); int DoExecute (void); int DoExecuteParm (char *parmName, char *tkn); int DoExclude (void); int DoExcludeParm (char *parmName, char *tkn); int DoFormat (void); int DoFormatParm (char *parmName, char *tkn); int DoHelp (void); int DoHelpParm (char *parmName, char *tkn); int DoInclude (void); int DoIncludeParm (char *parmName, char *tkn); int DoLog (void); int DoLogParm (char *parmName, char *tkn); int DoManual (void); int DoManualParm (char *parmName, char *tkn); int DoMatrix (void); int DoMatrixParm (char *parmName, char *tkn); int DoNexusParm (char *parmName, char *tkn); int DoOutgroup (void); int DoOutgroupParm (char *parmName, char *tkn); int DoPairs (void); int DoPairsParm (char *parmName, char *tkn); int DoPartition (void); int DoPartitionParm (char *parmName, char *tkn); int DoProps (void); int DoRestore (void); int DoRestoreParm (char *parmName, char *tkn); int DoRoot (void); int DoSet (void); int DoSetParm (char *parmName, char *tkn); int DoShowMatrix (void); int DoShowtree (void); int DoTaxaset (void); int DoTaxasetParm (char *parmName, char *tkn); int DoTaxaStat (void); int DoUserTree (void); int DoUserTreeParm (char *parmName, char *tkn); int DoVersion (void); int FindValidParam (char *tk, int *numMatches); int GetNumPartDivisions (int n); int GetUserHelp (char *helpTkn); int IsAmbig (int charCode, int dType); int IsMissing (int charCode, int dType); int NBits (int x); int NucID (char nuc); void PrintYesNo (int yn, char s[4]); int ProtID (char aa); int RemoveLastFromString (char *s1); int MBResID (char nuc); int SetPartitionInfo (int n); int StandID (char nuc); int StateCode_AA (int n); int StateCode_NUC4 (int n); int StateCode_Std (int n); void WhatVariableExp (unsigned long int exp, char *st); char WhichAA (int x); MrBFlt WhichCont (int x); char WhichRes (int x); char WhichStand (int x); /* globals */ int autoClose; /* autoclose */ int autoOverwrite; /* Overwrite or append outputfiles when nowarnings=yes */ Calibration *calibrationPtr; /* ptr to calibration being set */ CharInformation *charInfo; /* holds critical information about characters */ char *charSetNames; /* holds names of character sets */ Comptree comptreeParams; /* holds parameters for comparetree command */ Calibration constraintCalibration[MAX_NUM_CONSTRAINTS];/* holds calibration of constraints */ char *constraintNames; /* holds names of constraints */ int dataType; /* type of data */ int echoMB; /* flag used by Manual to prevent echoing */ unsigned long int expecting; /* variable denoting expected token type */ int foundNewLine; /* whether a new line has been found */ int inComment; /* flag for whether input stream is commented */ int inferAncStates; /* should ancestral states be inferred (y/n) */ int inferSiteRates; /* should site rates be inferred (y/n) */ int inMrbayesBlock; /* flag for whether we are in a mrbayes block */ int inSumtBlock; /* are we in the sumt block */ int inValidCommand; /* a useful flag set whenever you enter a cmd */ int isInAmbig, isInPoly; /* flags whether we are within () or {} */ int isTranslateDef; /* is a translation block defined */ int isUserTreeDefined; /* flag indicating whether user tree is found */ char logFileName[100]; /* name of the log file */ int logToFile; /* should screen output be logged to a file */ FILE *logFileFp; /* file pointer to log file */ char manFileName[100]; /* name of the file for the command help info */ int *matrix; /* matrix containing original data */ int matrixHasPoly; /* flag for whether matrix has polymorphisms */ int memAllocs[NUM_ALLOCS]; /* allocated memory flags */ int mode; /* mode of program (interactive/noninteractive) */ int noWarn; /* no warnings on overwriting files */ int numCharSets; /* holds number of character sets */ int numComments; /* counts how deeply nested a comment is */ int numDefinedConstraints; /* number of constraints defined */ int numDefinedPartitions; /* number of partitions defined */ int numOpenExeFiles; /* number of execute files open */ int numTaxaSets; /* holds number of taxa sets */ int outGroupNum; /* number of outgroup taxon */ ParmInfo paramTable[NUMPARAMS]; /* information on parameters */ char *partitionNames; /* hold names of partitions (first is "default") */ int partitionNum; /* number of current partition */ Plot plotParams; /* holds parameters for plot command */ int quitOnError; /* quit on error? */ MrBFlt relConstraintProbs[MAX_NUM_CONSTRAINTS];/* rel. probs. of constraint */ int replaceLogFile; /* should logfile be replace/appended to */ char spacer[10]; /* holds blanks for printing indentations */ Sump sumpParams; /* holds parameters for sump command */ Sumt sumtParams; /* holds parameters for sumt command */ TaxaInformation *taxaInfo; /* holds critical information about taxa */ char *taxaNames; /* holds name of taxa */ int *tempSet; /* temporarily holds defined character set */ char *taxaSetNames; /* holds names of taxa sets */ int theAmbigChar; /* int containing ambiguous character */ char *transFrom; /* translation block information */ char *transTo; /* translation block information */ int userBrlensDef; /* are the branch lengths on user tree defined */ Tree *userTree; /* user tree */ int longIntegerSize; /* size of an unsigned integer */ /* local (to this file) */ char *tokenP, token[CMD_STRING_LENGTH]; CmdType commands[] = { /* Information on commands initialization: 1 = Command number (cmdNumber) 2 = Command name (string) 3 = Special command (YES/NO) (specialCmd) 4 = Pointer to finishing function (fp) 5 = Number of valid parameters (numParms) 6 = List of valid parameters (parmList) 7 = Expecting (2^TokenType) (expect) (PARAMETER = 4; SEMICOLON = 32; ALPHA = 16384; ALPHA | QUESTIONMARK | DASH | NUMBER | ASTERISK | EXCLAMATIONMARK | PERCENT | WEIRD | SEMICOLON = 11715360; ALPHA | QUESTIONMARK | DASH | NUMBER | ASTERISK | EXCLAMATIONMARK | PERCENT | WEIRD | SEMICOLON | LEFTPAR | RIGHTPAR | LEFTCURL | RIGHTCURL = 112381728; PARAMETER | SEMICOLON = 36; NUMBER | ALPHA = 49152; ALPHA | SEMICOLON = 16416; EQUALSIGN = 8; NUMBER = 32768) 8 = Description of the command (cmdDescription) 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) 10 = Should the command be shown when "help" is typed (hiding). #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */ { 0, "#", NO, NULL, 1, {0}, 4, "", IN_FILE, HIDE }, { 1, "About", NO, DoAbout, 0, {-1}, 32, "Describes the program", IN_CMD, SHOW }, { 2, "Acknowledgments", NO, DoAcknowledgments, 0, {-1}, 32, "Shows program acknowledgments", IN_CMD, SHOW }, { 3, "Begin", NO, NULL, 3, {1,2,3}, 4, "Denotes beginning of block in file", IN_FILE, SHOW }, { 4, "Calibrate", NO, DoCalibrate, 1, {120}, 4, "Assigns dates to terminals or constrained nodes", IN_CMD, HIDE }, { 5, "Charset", NO, DoCharset, 1, {15}, 4, "Assigns a group of sites to a set", IN_CMD, SHOW }, { 6, "Charstat", NO, DoCharStat, 0, {-1}, 32, "Shows status of characters", IN_CMD, SHOW }, { 7, "Citations", NO, DoCitations, 0, {-1}, 32, "Appropriate citation of program", IN_CMD, SHOW }, { 8, "Comparetree", NO, DoCompareTree, 4, {127,128,129,130}, 36, "Compares the trees from two tree files", IN_CMD, SHOW }, { 9, "Constraint", NO, DoConstraints, 1, {66}, 4, "Defines a constraint on tree topology", IN_CMD, SHOW }, { 10, "Ctype", NO, DoCtype, 1, {65}, 4, "Assigns ordering for the characters", IN_CMD, SHOW }, { 11, "Databreaks", YES, DoBreaks, 1, {94}, 32768, "Defines nucleotide pairs (doublets) for stem models", IN_CMD, SHOW }, { 12, "Delete", YES, DoDelete, 1, {47}, 49152, "Deletes taxa from the analysis", IN_CMD, SHOW }, { 13, "Deroot", NO, DoDeroot, 0, {-1}, 32, "Deroots user tree", IN_CMD, SHOW }, { 14, "Dimensions", NO, DoDimensions, 2, {4,5}, 4, "Defines size of character matrix", IN_FILE, SHOW }, { 15, "Disclaimer", NO, DoDisclaimer, 0, {-1}, 32, "Describes program disclaimer", IN_CMD, SHOW }, { 16, "End", NO, DoEndBlock, 0, {-1}, 32, "Denotes end of a block in file", IN_FILE, SHOW }, { 17, "Endblock", NO, DoEndBlock, 0, {-1}, 32, "Alternative way of denoting end of a block", IN_FILE, SHOW }, { 18, "Exclude", YES, DoExclude, 1, {45}, 49152, "Excludes sites from the analysis", IN_CMD, SHOW }, { 19, "Execute", YES, DoExecute, 1, {12}, 16384, "Executes a file", IN_CMD, SHOW }, { 20, "Format", NO, DoFormat, 5, {6,7,8,9,10}, 4, "Defines character format in data block", IN_FILE, SHOW }, { 21, "Help", YES, DoHelp, 1, {50}, 16416, "Provides detailed description of commands", IN_CMD, SHOW }, { 22, "Include", YES, DoInclude, 1, {46}, 49152, "Includes sites", IN_CMD, SHOW }, { 23, "Link", NO, DoLink, 16, {55,56,57,58,59,60,61,62,63,72,73,74,75,76,106,119}, 4, "Links parameters across character partitions", IN_CMD, SHOW }, { 24, "Log", NO, DoLog, 5, {86,87,88,89,90}, 4, "Logs screen output to a file", IN_CMD, SHOW }, { 25, "Lset", NO, DoLset, 14, {28,29,30,31,32,33,34,40,51,52,53,91,92,131}, 4, "Sets the parameters of the likelihood model", IN_CMD, SHOW }, { 26, "Manual", NO, DoManual, 1, {127}, 36, "Prints a command reference to a text file", IN_CMD, SHOW }, { 27, "Matrix", YES, DoMatrix, 1, {11},112381728, "Defines matrix of characters in data block", IN_FILE, SHOW }, { 28, "Mcmc", NO, DoMcmc, 37, {17,18,19,20,21,22,23,24,25,26,27,85,99,113,114,115,116,117,132,143,144,145,149,150,151,152,153, 154,155,156,157,158,159,160,161,167,170}, 36, "Starts Markov chain Monte Carlo analysis", IN_CMD, SHOW }, { 29, "Mcmcp", NO, DoMcmcp, 37, {17,18,19,20,21,22,23,24,25,26,27,85,99,113,114,115,116,117,132,143,144,145,149,150,151,152,153, 154,155,156,157,158,159,160,161,167,170}, 4, "Sets the parameters of a chain (without starting analysis)", IN_CMD, SHOW }, { 30, "Outgroup", YES, DoOutgroup, 1, {79}, 49152, "Changes outgroup taxon", IN_CMD, SHOW }, { 31, "Pairs", YES, DoPairs, 1, {93}, 32768, "Defines nucleotide pairs (doublets) for stem models", IN_CMD, SHOW }, { 32, "Partition", NO, DoPartition, 1, {16}, 4, "Assigns a character partition", IN_CMD, SHOW }, { 33, "Plot", NO, DoPlot, 4, {107,108,109,110}, 36, "Plots parameters from MCMC analysis", IN_CMD, SHOW }, { 34, "Prset", NO, DoPrset, 30, {35,36,37,38,39,41,42,43,44,54,64,67,68,69,70,71,77,101,102,103,104,105,111,112,118,121,122,133, 134,169}, 4, "Sets the priors for the parameters", IN_CMD, SHOW }, { 35, "Props", NO, DoProps, 0, {-1}, 32, "Set proposal probabilities", IN_CMD, SHOW }, { 36, "Quit", NO, DoQuit, 0, {-1}, 32, "Quits the program", IN_CMD, SHOW }, { 37, "Report", NO, DoReport, 7, {123,124,125,134,135,136,137}, 4, "Controls how model parameters are reported", IN_CMD, SHOW }, { 38, "Restore", YES, DoRestore, 1, {48}, 49152, "Restores taxa", IN_CMD, SHOW }, { 39, "Root", NO, DoRoot, 0, {-1}, 32, "Roots user tree", IN_CMD, SHOW }, { 40, "Set", NO, DoSet, 5, {13,14,95,146,171}, 4, "Sets run conditions and defines active data partition", IN_CMD, SHOW }, { 41, "Showmatrix", NO, DoShowMatrix, 0, {-1}, 32, "Shows current character matrix", IN_CMD, SHOW }, { 42, "Showmodel", NO, DoShowModel, 0, {-1}, 32, "Shows model settings", IN_CMD, SHOW }, { 43, "Showtree", NO, DoShowtree, 0, {-1}, 32, "Shows user tree", IN_CMD, SHOW }, { 44, "Sump", NO, DoSump, 9, {97,98,138,139,140,141,142,162,163}, 36, "Summarizes parameters from MCMC analysis", IN_CMD, SHOW }, { 45, "Sumt", NO, DoSumt, 11, {81,82,83,96,100,147,148,164,165,166,168}, 36, "Summarizes trees from MCMC analysis", IN_CMD, SHOW }, { 46, "Taxastat", NO, DoTaxaStat, 0, {-1}, 32, "Shows status of taxa", IN_CMD, SHOW }, { 47, "Taxset", NO, DoTaxaset, 1, {49}, 4, "Assigns a group of taxa to a set", IN_CMD, SHOW }, { 48, "Translate", YES, DoTranslate, 1, {84}, 49152, "Defines alternative names for taxa", IN_FILE, SHOW }, { 49, "Tree", NO, DoTree, 1, {80}, 4, "Defines a tree from MCMC analysis", IN_FILE, SHOW }, { 50, "Unlink", NO, DoUnlink, 16, {55,56,57,58,59,60,61,62,63,72,73,74,75,76,106,119}, 4, "Unlinks parameters across character partitions", IN_CMD, SHOW }, { 51, "Usertree", YES, DoUserTree, 1, {78}, 8, "Defines a single user tree", IN_CMD, SHOW }, { 52, "Version", NO, DoVersion, 0, {-1}, 32, "Shows program version", IN_CMD, SHOW }, /* NOTE: If you add a command here, make certain to change NUMCOMMANDS (above, in this file) appropriately! */ { 999, NULL, NO, NULL, 0, {-1}, 32, "", IN_CMD, HIDE } }; int inDataBlock, inForeignBlock, isInterleaved, isFirstMatrixRead, isFirstInterleavedBlock, taxonCount, fromI, toJ, everyK, foundDash, foundSlash, foundFirst, isMixed, whichPartition, isNegative, numPartitions, charOrdering, foundExp, foundColon, isFirstNode, nextAvailableNode, pairId, firstPair; char gapId, missingId, matchId, tempSetName[100]; CmdType *commandPtr; ParmInfoPtr paramPtr; TreeNode *pPtr, *qPtr; int AddToSet (int i, int j, int k, int id) { int m, n; if (id <= 0) { MrBayesPrint ("%s The id for a temporary set should be greater than 0\n", spacer); return (ERROR); } if (i < 0 && j < 0) return (ERROR); else if (i < 0 && j >= 0) return (ERROR); else if (i >= 0 && j < 0) { if (k >= 0) return (ERROR); else { if (tempSet[i] != 0) { MrBayesPrint ("%s Character %d defined more than once\n", spacer, i+1); return (ERROR); } tempSet[i] = id; } } else if (i >= 0 && j >= 0) { if (k < 0) { for (m=i; m<=j; m++) { if (tempSet[m] != 0) { MrBayesPrint ("%s Character %d defined more than once\n", spacer, m+1); return (ERROR); } tempSet[m] = id; } } else { n = k; for (m=i; m<=j; m++) { if (n % k == 0) { if (tempSet[m] != 0) { MrBayesPrint ("%s Character %d defined more than once\n", spacer, m+1); return (ERROR); } tempSet[m] = id; } n++; } } } return (NO_ERROR); } int AddToString (char *s1, char *s2, int *x) { int i, j, startI=0, numPrev; /* s1 is the character string that should be appended to character string s2 We assume that the end of each character string has a "|". */ i = numPrev = 0; while (s2[i] != '\0') { if (s2[i] == '|') numPrev++; i++; } if (numPrev == 0) startI = 0; else { i = j = 0; while (s2[i] != '\0') { if (s2[i] == '|') j++; i++; if (j == numPrev) { startI = i; break; } } } if (s2[startI] == '\0') { MrBayesPrint ("%s String is too full (1 %d)\n", spacer, startI); return (ERROR); } i = startI; j = 0; while(s1[j] != '\0') { s2[i++] = s1[j++]; if (s2[i] == '\0') { MrBayesPrint ("%s String is too full (2 %d)\n", spacer, i); return (ERROR); } } s2[i] = '|'; *x = numPrev + 1; return (NO_ERROR); } int AllocMatrix (void) { int i, j, tempSetSize; if (memAllocs[ALLOC_MATRIX] == YES) FreeMatrix(); matrix = (int *)SafeMalloc((size_t) (numTaxa * numChar * sizeof(int))); if (!matrix) { MrBayesPrint ("%s Problem allocating matrix (%d)\n", spacer, numTaxa * numChar * sizeof(int)); goto errorExit; } for (i=0; i numTaxa) tempSetSize = numChar; else tempSetSize = numTaxa; tempSet = (int *)SafeMalloc((size_t) (tempSetSize * sizeof(int))); if (!tempSet) { MrBayesPrint ("%s Problem allocating tempSet (%d)\n", spacer, tempSetSize * sizeof(int)); goto errorExit; } for (i=0; i>= 1; return (i); } int CheckInitialPartitions (void) { int i; for (i=0; i numPartitions) { MrBayesPrint ("%s The partition for site %d is incorrect\n", spacer, i+1); return (ERROR); } } return (NO_ERROR); } int CheckStringValidity (char *s) { int i, numUnknownChars, tempNumComments, tempInComment; char temp[100]; i = 0; numUnknownChars = 0; tempNumComments = numComments; tempInComment = inComment; while(s[i] != '\0') { if (tempInComment == NO) { if ( !IsIn(s[i],"=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789.;:,#()[]?-*/'\\'!%\"&~+^$@|{}`>< ") ) { if (IsWhite(s[i]) == 1 || IsWhite(s[i]) == 2) { } else { if ( commandPtr == NULL) return (ERROR); MrBayesPrint ("%s Unknown character \"%c\" (ASCII code %d)\n", spacer, s[i], s[i]); if (!strcmp(commandPtr->string,"Matrix")) { if (foundNewLine == NO) { MrBayesPrint ("%s The error is in character %d for taxon %s\n", spacer, taxaInfo[taxonCount-1].charCount+i+1); } else { if (taxonCount == 0) MrBayesPrint ("%s The error is in the first taxon name\n", spacer); else { GetNameFromString (taxaNames, temp, taxonCount); if (isInterleaved == NO) MrBayesPrint ("%s The error is in the name of the taxon following taxon %s\n", spacer, temp); else { MrBayesPrint ("%s The error is in the name of the taxon following taxon %s\n", spacer, temp); MrBayesPrint ("%s in one of the interleaved data blocks\n", spacer); } } } } else if (!strcmp(commandPtr->string,"Execute")) { MrBayesPrint ("%s Assuming irrelevant characters at beginning of file; processing continues\n", spacer); return (NO_ERROR); } return (ERROR); } } if (s[i]=='[') { tempInComment = YES; tempNumComments++; } } else if (tempInComment == YES) { if (s[i]==']') { tempNumComments--; if (tempNumComments == 0) tempInComment = NO; } } i++; } if (numUnknownChars > 0) return (ERROR); else return (NO_ERROR); } int CheckString (char *s1, char *s2, int *x) { int i, j, len1, len2, numOfStr, foundString, isIdentical, nDiff; char tempStr[100]; /* This function checks a string s1 against a list of names contained in s2. The list of names in s2 is formatted like: "name1|name2|name3| \0" This string contains only three names and the names are separated by a "|". When we go through the list of names, we know that we have found the end of a name when we find "|" and that we have found the end of the list of names when we find "\0" or " " (a blank). The command returns an ERROR if a match was not found. Otherwise, a NO_ERROR is returned and *x is the number in the list (s2) that matched s1. The number, x, is indexed 1, 2, 3, ... */ len1 = (int) strlen(s1); i = j = numOfStr = 0; foundString = NO; while (s2[i] != '\0' && s2[i] != ' ') { if (j >= 100 - 2) { return (ERROR); } if (s2[i] != '|' && s2[i] != '\0' && s2[i] != ' ' && j < 100 - 2) { tempStr[j++] = s2[i]; } else { tempStr[j++] = '\0'; len2 = (int) strlen(tempStr); isIdentical = YES; if (len1 != len2) { isIdentical = NO; } else { nDiff = 0; for (j=0; j 0) isIdentical = NO; } if (isIdentical == YES) { foundString = YES; *x = numOfStr + 1; break; } j = 0; numOfStr++; } i++; } if (foundString == NO) return (ERROR); return (NO_ERROR); } int Dex (TreeNode *p) { return (p == NULL) ? -1 : p->index; } int DoAbout (void) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" About the program \n"); MrBayesPrint (" \n"); MrBayesPrint (" MrBayes is a program for the Bayesian estimation of phylogeny. Bayesian \n"); MrBayesPrint (" inference of phylogeny is based upon the posterior probability distribution \n"); MrBayesPrint (" of trees. Trees are labelled T1, T2, ..., Tn, where n is the number of \n"); MrBayesPrint (" possible trees. The posterior probability of the i-th tree is calculated \n"); MrBayesPrint (" using Bayes\'s formula as \n"); MrBayesPrint (" \n"); MrBayesPrint (" Pr[Ti | X] = Pr[X | Ti] X Pr[Ti] / Pr[X] \n"); MrBayesPrint (" \n"); MrBayesPrint (" where X is a character matrix. Here, \"Pr[Ti | X]\" is the posterior \n"); MrBayesPrint (" probability of the i-th tree, \"Pr[X | Ti]\" is the likelihood of the \n"); MrBayesPrint (" i-th tree, and \"Pr[Ti]\" is the prior probability of the i-th tree. The \n"); MrBayesPrint (" denominator of Bayes\'s formula (\"Pr[X]\") is a normalizing constant that \n"); MrBayesPrint (" involves a summation over all possible trees. The likelihood, as described \n"); MrBayesPrint (" above, cannot be calculated with knowledge of only the tree\'s topology. You \n"); MrBayesPrint (" also need to have information on the lenths of the branches and on the \n"); MrBayesPrint (" mechanism of character change. Hence, the likelihood (\"Pr[X | Ti]\") \n"); MrBayesPrint (" involves a multidimensional integral over all possible combinations of \n"); MrBayesPrint (" branch lengths and substitution model parameters. \n"); MrBayesPrint (" \n"); MrBayesPrint (" In practice, it is impossible to calculate the posterior probability dist- \n"); MrBayesPrint (" ribution of trees analytically. Instead, the posterior probability \n"); MrBayesPrint (" of trees must be approximated. MrBayes uses a method called Markov chain \n"); MrBayesPrint (" Monte Carlo (MCMC) to approximate the posterior probability of trees. \n"); MrBayesPrint (" The object of MCMC is to construct a Markov chain that has as its state \n"); MrBayesPrint (" space the parameters of the phylogenetic model and a stationary distribution \n"); MrBayesPrint (" that is the posterior probability distribution of trees. MCMC takes valid, \n"); MrBayesPrint (" albeit dependent, samples from the posterior probability distribution of \n"); MrBayesPrint (" trees. The fraction of the time any tree appears in this sample is a \n"); MrBayesPrint (" valid approximation of the posterior probability of the tree. MrBayes keeps \n"); MrBayesPrint (" track of all the parameters of the phylogenetic model. The trees (with branch \n"); MrBayesPrint (" lengths) that were sampled by the MCMC procedure are saved in one file \n"); MrBayesPrint (" (a file with a \".t\" extension) whereas the parameters of the model of \n"); MrBayesPrint (" character change are saved in another file (a file with a \".p\" ext- \n"); MrBayesPrint (" ension). You can summarize the results in the \".t\" and \".p\" files \n"); MrBayesPrint (" using the \"sumt\" and \"sump\" commands, respectively. \n"); MrBayesPrint (" \n"); MrBayesPrint (" MrBayes is cowritten by John Huelsenbeck and Fredrik Ronquist. It is \n"); MrBayesPrint (" rather unusual to find a program of this sort that has multiple authors. \n"); MrBayesPrint (" However, each author brings unique strengths to the development of the \n"); MrBayesPrint (" program. Originally, the program was started by JH in August of \n"); MrBayesPrint (" 2000 and was intended to be distributed to a small number of people. \n"); MrBayesPrint (" In March of 2001, Fredrik started making contributions to the program. \n"); MrBayesPrint (" The contributions were of such a significant nature that he was made \n"); MrBayesPrint (" a coauthor of the program. In particular, FR improved the speed of the \n"); MrBayesPrint (" likelihood functions of the program and included new proposal mechanisms \n"); MrBayesPrint (" for changing trees. The newest version of the program, v%s, is a \n", VERSION_NUMBER); MrBayesPrint (" completely rewritten version of the earlier program, and has more \n"); MrBayesPrint (" integrally included FR\'s contributions. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); return (NO_ERROR); } int DoAcknowledgments (void) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Acknowledgments \n"); MrBayesPrint (" \n"); MrBayesPrint (" JPH and FR would like to thank Gautam Altekar, Andrea Betancourt, Jon \n"); MrBayesPrint (" Bollback, Barry Hall, Jimmy McGuire, Rasmus Nielsen, David Swofford, \n"); MrBayesPrint (" Johan Nylander, Mikael Thollesson, and Derrick Zwickl for help during the \n"); MrBayesPrint (" development of this program. Gautam Altekar, especially, was instrumental \n"); MrBayesPrint (" in getting the parallel version of the program working. \n"); MrBayesPrint (" \n"); MrBayesPrint (" Our wives -- Edna Huelsenbeck and Eva Ronquist -- showed extraordinary \n"); MrBayesPrint (" patience with us while we spent many late nights programming. \n"); MrBayesPrint (" \n"); MrBayesPrint (" JPH was supported by NSF grants DEB-007540 and MCB-0075404 and a Wenner- \n"); MrBayesPrint (" Gren scholarship while writing this program. FR was supported by grants \n"); MrBayesPrint (" from the Swedish Natural Science Research Council and the Swedish Research \n"); MrBayesPrint (" Council. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); return (NO_ERROR); } int DoBeginParm (char *parmName, char *tkn) { if (expecting == Expecting(PARAMETER)) { /* set Data (inDataBlock) *************************************************************/ if (!strcmp(parmName, "Data")) { if (FreeMatrix () == ERROR) return (ERROR); MrBayesPrint (" Reading data block\n"); inDataBlock = YES; expecting = Expecting(SEMICOLON); strcpy (spacer, " "); } /* set Mrbayes (inMrbayesBlock) *******************************************************/ else if (!strcmp(parmName, "Mrbayes")) { MrBayesPrint (" Reading MrBayes block\n"); inMrbayesBlock = YES; expecting = Expecting(SEMICOLON); strcpy (spacer, " "); } /* set Foreign (inForeignBlock) *******************************************************/ else { MrBayesPrint (" Skipping \"%s\" block\n", tkn); inForeignBlock = YES; expecting = Expecting(SEMICOLON); strcpy (spacer, ""); } } else return (ERROR); return (NO_ERROR); } int DoBreaks (void) { int i, numBreaks; numBreaks = 0; for (i=0; i 0) { if (numBreaks == 1) MrBayesPrint ("%s One data break found after character ", spacer, numBreaks); else MrBayesPrint ("%s %d data breaks found after characters: ", spacer, numBreaks); for (i=0; i numChar) { MrBayesPrint ("%s Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar); for (i=0; i 1) { MrBayesPrint ("%s Both a taxon and a constraint named ""%s"" encountered -- please rename one\n", spacer, tkn); return (ERROR); } if (calibrationPtr->prior != unconstrained) { MrBayesPrint ("%s Resetting previous calibration for ""%s""\n", spacer, tkn); } /* reset the values of the calibration */ strcpy (calibrationPtr->name, "Unconstrained"); calibrationPtr->prior = unconstrained; calibrationPtr->lower = -1.0; calibrationPtr->upper = -1.0; calibrationPtr->age = -1.0; calibrationPtr->offset = -1.0; calibrationPtr->lambda = -1.0; /* get ready to find the equal sign */ expecting = Expecting(EQUALSIGN); } else if (expecting == Expecting(EQUALSIGN)) { /* get ready to find the calibration prior */ expecting = Expecting(ALPHA); } else if (expecting == Expecting(ALPHA)) { /* set the calibration prior type */ if (IsArgValid(tkn,tempStr) == NO_ERROR) { if (!strcmp (tempStr, "Uniform")) calibrationPtr->prior = uniform; else if (!strcmp (tempStr, "Offsetexponential")) calibrationPtr->prior = offsetExponential; else if (!strcmp (tempStr, "Fixed")) calibrationPtr->prior = fixed; else /* if (!strcmp (tempStr, "Unconstrained")) */ calibrationPtr->prior = unconstrained; strcpy (calibrationPtr->name, tempStr); if (calibrationPtr->prior == unconstrained) expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); else expecting = Expecting(LEFTPAR); } else { MrBayesPrint ("%s Invalid calibration prior argument \n", spacer); return (ERROR); } } else if (expecting == Expecting(LEFTPAR)) { strcat (calibrationPtr->name, "("); expecting = Expecting(NUMBER); } else if (expecting == Expecting(NUMBER)) { if (calibrationPtr->prior == fixed) { sscanf (tkn, "%lf", &tempD); if (tempD <= 0.0) { MrBayesPrint ("%s Age must be positive\n", spacer); calibrationPtr->prior = unconstrained; return (ERROR); } calibrationPtr->age = tempD; expecting = Expecting(RIGHTPAR); } else if (calibrationPtr->prior == uniform) { sscanf (tkn, "%lf", &tempD); if (tempD <= 0.0) { MrBayesPrint ("%s Age must be positive\n", spacer); calibrationPtr->prior = unconstrained; return (ERROR); } if (calibrationPtr->lower < 0.0) { calibrationPtr->lower = tempD; expecting = Expecting(COMMA); } else { if (tempD <= calibrationPtr->lower) { MrBayesPrint ("%s Maximum age must be larger than minimum age\n", spacer); calibrationPtr->prior = unconstrained; return (ERROR); } calibrationPtr->upper = tempD; expecting = Expecting(RIGHTPAR); } } else if (calibrationPtr->prior == offsetExponential) { sscanf (tkn, "%lf", &tempD); if (calibrationPtr->offset < 0.0) { if (tempD <= 0.0) { MrBayesPrint ("%s Offset age must be positive\n", spacer); calibrationPtr->prior = unconstrained; return (ERROR); } calibrationPtr->offset = tempD; expecting = Expecting(COMMA); } else { if (tempD <= MIN_OFFSET_EXP_LAMBDA) { MrBayesPrint ("%s Offset exponential lambda parameter must be larger than %lf\n", spacer, MIN_OFFSET_EXP_LAMBDA); calibrationPtr->prior = unconstrained; return (ERROR); } else if (tempD >= MAX_OFFSET_EXP_LAMBDA) { MrBayesPrint ("%s Offset exponential lambda parameter must be smaller than %lf\n", spacer, MAX_OFFSET_EXP_LAMBDA); calibrationPtr->prior = unconstrained; return (ERROR); } calibrationPtr->lambda = tempD; expecting = Expecting(RIGHTPAR); } } sprintf (s, "%1.2lf", tempD); strcat (calibrationPtr->name, s); } else if (expecting == Expecting(COMMA)) { strcat (calibrationPtr->name, ","); expecting = Expecting(NUMBER); } else if (expecting == Expecting(RIGHTPAR)) { strcat (calibrationPtr->name, ")"); if (isTaxon == YES) MrBayesPrint ("%s Setting age of taxon %s to %s\n", spacer, nodeName, calibrationPtr->name); else MrBayesPrint ("%s Setting age of constraint node %s to %s\n", spacer, nodeName, calibrationPtr->name); /* get ready to find more calibrated nodes or taxa, if present */ expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); return (NO_ERROR); } int DoCharset (void) { int i, howMany; /* first add name to charSetName */ if (AddToString (tempSetName, charSetNames, &howMany) == ERROR) { MrBayesPrint ("%s Problem adding charset %s to list\n", spacer, tempSetName); return (ERROR); } if (howMany != numCharSets + 1) { MrBayesPrint ("%s Problem adding charset %s to list\n", spacer, tempSetName); if (RemoveLastFromString (charSetNames) == ERROR) return (ERROR); return (ERROR); } /* add set to tempSet */ if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) { if (RemoveLastFromString (charSetNames) == ERROR) return (ERROR); return (ERROR); } } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) { if (RemoveLastFromString (charSetNames) == ERROR) return (ERROR); return (ERROR); } } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) { if (RemoveLastFromString (charSetNames) == ERROR) return (ERROR); return (ERROR); } } /* merge tempSet with charset */ for (i=0; i 99) { MrBayesPrint ("%s Charset name is too long\n", spacer); return (ERROR); } /* check to see if the name has already been used as a charset */ if (numCharSets > 1) { if (CheckString (tkn, charSetNames, &howMany) == ERROR) { /* if the charset name has not been used, then we should have an ERROR returned */ /* we _want_ to be here */ } else { MrBayesPrint ("%s Charset name has been used previously\n", spacer); return (ERROR); } } else if (numCharSets > MAX_NUM_CHARSETS) { MrBayesPrint ("%s You cannot define more than %d charsets\n", spacer, MAX_NUM_CHARSETS); return (ERROR); } /* add the name to the character set */ strcpy (tempSetName, tkn); /* clear tempSet */ for (i=0; i numChar) { MrBayesPrint ("%s Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar); return (ERROR); } tempInt--; if (foundDash == YES) { if (fromI >= 0) toJ = tempInt; else { MrBayesPrint ("%s Improperly formatted charset\n", spacer); return (ERROR); } foundDash = NO; } else if (foundSlash == YES) { tempInt++; if (tempInt <= 1) { MrBayesPrint ("%s Improperly formatted charset\n", spacer); return (ERROR); } if (fromI >= 0 && toJ >= 0 && fromI < toJ) everyK = tempInt; else { MrBayesPrint ("%s Improperly formatted charset\n", spacer); return (ERROR); } foundSlash = NO; } else { if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; } else if (fromI < 0 && toJ < 0) { fromI = tempInt; } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else { MrBayesPrint ("%s Improperly formatted charset\n", spacer); { return (ERROR); } } } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(SEMICOLON); expecting |= Expecting(DASH); expecting |= Expecting(BACKSLASH); } else if (expecting == Expecting(DASH)) { foundDash = YES; expecting = Expecting(NUMBER); } else if (expecting == Expecting(BACKSLASH)) { foundSlash = YES; expecting = Expecting(NUMBER); } else return (ERROR); return (NO_ERROR); } int DoCharStat (void) { int i, j, numDivs; char tempName[100]; if (defMatrix == NO) { MrBayesPrint ("%s A character matrix must be defined first\n", spacer); return (ERROR); } if (numDefinedPartitions == 1) MrBayesPrint ("%s 1 character partition defined:\n", spacer, numDefinedPartitions); else MrBayesPrint ("%s %d character partitions defined:\n", spacer, numDefinedPartitions); for (i=0; i 0) { /* find paired character */ for (j=0; j= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) { if (RemoveLastFromString (constraintNames) == ERROR) return (ERROR); return (ERROR); } } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) { if (RemoveLastFromString (constraintNames) == ERROR) return (ERROR); return (ERROR); } } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) { if (RemoveLastFromString (constraintNames) == ERROR) return (ERROR); return (ERROR); } } /* check that this is not a stupid constraint */ howMany = 0; for (i=0; i= numTaxa) { MrBayesPrint ("%s This constraint includes all taxa and will not be defined\n", spacer); if (RemoveLastFromString (constraintNames) == ERROR) return (ERROR); return (ERROR); } else if (howMany == 0) { MrBayesPrint ("%s This constraint does not include any taxa and will not be defined\n", spacer); if (RemoveLastFromString (constraintNames) == ERROR) return (ERROR); return (ERROR); } else if (howMany == 1 || howMany == numTaxa - 1) MrBayesPrint ("%s This is a trivial constraint for unrooted trees\n", spacer); /* merge tempSet with constraints */ for (i=0; i 99) { MrBayesPrint ("%s Constraint name is too long\n", spacer); return (ERROR); } /* check to see if the name has already been used as a taxset */ if (numDefinedConstraints > 0) { if (CheckString (tkn, constraintNames, &howMany) == ERROR) { /* if the constraint name has not been used, then we should have an ERROR returned */ /* we _want_ to be here */ } else { MrBayesPrint ("%s Constraint name has been used previously\n", spacer); return (ERROR); } } else if (numDefinedConstraints > 30) { MrBayesPrint ("%s You cannot define more than 30 constraints\n", spacer); return (ERROR); } /* add the name to the temporary constraint names string */ strcpy (tempSetName, tkn); /* clear tempSet */ for (i=0; i numTaxa) { MrBayesPrint ("%s Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa); return (ERROR); } } tempInt--; if (foundDash == YES) { if (fromI >= 0) toJ = tempInt; else { MrBayesPrint ("%s Improperly formatted constraint\n", spacer); return (ERROR); } foundDash = NO; } else if (foundSlash == YES) { tempInt++; if (tempInt <= 1) { MrBayesPrint ("%s Improperly formatted constraint\n", spacer); return (ERROR); } if (fromI >= 0 && toJ >= 0 && fromI < toJ) everyK = tempInt; else { MrBayesPrint ("%s Improperly formatted constraint\n", spacer); return (ERROR); } foundSlash = NO; } else { if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; } else if (fromI < 0 && toJ < 0) { fromI = tempInt; } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else { MrBayesPrint ("%s Improperly formatted constraint\n", spacer); { return (ERROR); } } } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(SEMICOLON); expecting |= Expecting(DASH); expecting |= Expecting(BACKSLASH); } } else if (expecting == Expecting(BACKSLASH)) { foundSlash = YES; expecting = Expecting(NUMBER); } else return (ERROR); return (NO_ERROR); } int DoCtype (void) { int i, foundIllegal, marks[5], numAppliedTo; /* add set to tempSet */ if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } /* merge tempSet with ctype */ numAppliedTo = 0; for (i=0; i<5; i++) marks[i] = NO; for (i=0; i 0) { MrBayesPrint ("%s Ctype was applied to %d standard characters\n", spacer, numAppliedTo); } else { MrBayesPrint ("%s No standard characters found to apply ctype to\n", spacer); } # if 0 for (i=0; i numChar) { MrBayesPrint ("%s Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar); return (ERROR); } tempInt--; if (foundDash == YES) { if (fromI >= 0) toJ = tempInt; else { MrBayesPrint ("%s Improperly formatted ctype\n", spacer); return (ERROR); } foundDash = NO; } else if (foundSlash == YES) { tempInt++; if (tempInt <= 1) { MrBayesPrint ("%s Improperly formatted ctype\n", spacer); return (ERROR); } if (fromI >= 0 && toJ >= 0 && fromI < toJ) everyK = tempInt; else { MrBayesPrint ("%s Improperly formatted ctype\n", spacer); return (ERROR); } foundSlash = NO; } else { if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; } else if (fromI < 0 && toJ < 0) { fromI = tempInt; } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else { MrBayesPrint ("%s Improperly formatted ctype\n", spacer); { return (ERROR); } } } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(SEMICOLON); expecting |= Expecting(DASH); expecting |= Expecting(BACKSLASH); } else if (expecting == Expecting(DASH)) { foundDash = YES; expecting = Expecting(NUMBER); } else if (expecting == Expecting(BACKSLASH)) { foundSlash = YES; expecting = Expecting(NUMBER); } else return (ERROR); return (NO_ERROR); } int DoDelete (void) { int i, alreadyDone; MrBayesPrint ("%s Excluding taxa\n", spacer); /* add set to tempSet */ if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } /* merge tempSet with taxset */ alreadyDone = NO; for (i=0; i= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } tempSet[howMany-1] = 1; } } foundDash = NO; fromI = toJ = everyK = -1; expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(SEMICOLON); } else if (expecting == Expecting(NUMBER)) { if (strlen(tkn) == 1 && !strcmp(tkn, ".")) tempInt = numTaxa; else { sscanf (tkn, "%d", &tempInt); if (tempInt <= 0 || tempInt > numTaxa) { MrBayesPrint ("%s Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa); return (ERROR); } } tempInt--; if (foundDash == YES) { if (fromI >= 0) toJ = tempInt; else { MrBayesPrint ("%s Improperly formatted delete set\n", spacer); return (ERROR); } foundDash = NO; } else { if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; } else if (fromI < 0 && toJ < 0) { fromI = tempInt; } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else { MrBayesPrint ("%s Improperly formatted delete set\n", spacer); { return (ERROR); } } } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(SEMICOLON); expecting |= Expecting(DASH); } else if (expecting == Expecting(DASH)) { foundDash = YES; expecting = Expecting(NUMBER); } else return (ERROR); return (NO_ERROR); MrBayesPrint ("%s", parmName); /*just because I am tired of seeing the unused parameter error msg */ } int DoDeroot (void) { if (isUserTreeDefined == NO) { MrBayesPrint (" No tree in memory\n", spacer); return (ERROR); } if (userTree->isRooted == YES) { if (DerootTree (userTree, outGroupNum) == ERROR) return (ERROR); MrBayesPrint ("%s Derooting user tree\n", spacer); } else MrBayesPrint ("%s Tree is already unrooted\n", spacer); return (NO_ERROR); } int DoDimensions (void) { if (defTaxa == NO || defChars == NO) { MrBayesPrint ("%s Expecting both Ntax and Nchar to be defined\n", spacer); return (ERROR); } if (inDataBlock == NO) { MrBayesPrint ("%s Dimensions can only be defined in a data block\n", spacer); return (ERROR); } /* allocate matrix */ if (AllocMatrix() == ERROR) return (ERROR); MrBayesPrint ("%s Matrix has %d taxa and %d characters\n", spacer, numTaxa, numChar); return (NO_ERROR); } int DoDimensionsParm (char *parmName, char *tkn) { if (expecting == Expecting(PARAMETER)) { expecting = Expecting(EQUALSIGN); } else { /* set Ntax (numTaxa) *****************************************************************/ if (!strcmp(parmName, "Ntax")) { if (expecting == Expecting(EQUALSIGN)) expecting = Expecting(NUMBER); else if (expecting == Expecting(NUMBER)) { sscanf (tkn, "%d", &numTaxa); defTaxa = YES; expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } /* set Nchar (numChar) ****************************************************************/ else if (!strcmp(parmName, "Nchar")) { if (expecting == Expecting(EQUALSIGN)) expecting = Expecting(NUMBER); else if (expecting == Expecting(NUMBER)) { sscanf (tkn, "%d", &numChar); defChars = YES; expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } else return (ERROR); } return (NO_ERROR); } int DoDisclaimer (void) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Disclaimer \n"); MrBayesPrint (" \n"); MrBayesPrint (" Copyright 2003 by John P. Huelsenbeck and Fredrik Ronquist \n"); MrBayesPrint (" \n"); MrBayesPrint (" This software package is provided \"as is\" and without a warranty of any \n"); MrBayesPrint (" kind. In no event shall the authors be held responsible for any damage \n"); MrBayesPrint (" resulting from the use of this software. The program--including source code, \n"); MrBayesPrint (" example data sets, and executables--is distributed free of charge for \n"); MrBayesPrint (" academic use only. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); return (NO_ERROR); } int DoEndBlock (void) { if (inMrbayesBlock == YES) { MrBayesPrint (" Exiting MrBayes block\n"); inMrbayesBlock = NO; } else if (inDataBlock == YES) { MrBayesPrint (" Exiting data block\n"); inDataBlock = NO; } else if (inForeignBlock == YES) { MrBayesPrint (" Exiting foreign block\n"); inForeignBlock = NO; } else { MrBayesPrint (" Unknown \"end\" statement\n"); return (ERROR); } return (NO_ERROR); } int DoExecute (void) { int c, i, rc, lineTerm, longestLineLength, nErrors; char *s; FILE *fp; # if defined (MPI_ENABLED) int sumErrors; # endif nErrors = 0; numOpenExeFiles++; s = NULL; if (numOpenExeFiles > 1) MrBayesPrint ("\n%s Executing file \"%s\"\n", spacer, inputFileName); else MrBayesPrint ("%s Executing file \"%s\"\n", spacer, inputFileName); /* open binary file */ if ((fp = OpenBinaryFileR(inputFileName)) == NULL) nErrors++; /* set indentation to 0 */ strcpy (spacer, ""); # if defined (MPI_ENABLED) MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if (sumErrors > 0) { MrBayesPrint ("%s There was an error on at least one processor\n", spacer); goto errorExit; } # else if (nErrors > 0) goto errorExit; # endif /* find out what type of line termination is used */ lineTerm = LineTermType (fp); if (lineTerm == LINETERM_MAC) MrBayesPrint ("%s Macintosh line termination\n", spacer); else if (lineTerm == LINETERM_DOS) MrBayesPrint ("%s DOS line termination\n", spacer); else if (lineTerm == LINETERM_UNIX) MrBayesPrint ("%s UNIX line termination\n", spacer); else { MrBayesPrint ("%s Unknown line termination\n", spacer); nErrors++; } # if defined (MPI_ENABLED) MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if (sumErrors > 0) { MrBayesPrint ("%s There was an error on at least one processor\n", spacer); goto errorExit; } # else if (nErrors > 0) goto errorExit; # endif /* find length of longest line */ longestLineLength = LongestLine (fp); MrBayesPrint ("%s Longest line length = %d\n", spacer, longestLineLength); longestLineLength += 50; /* check that longest line is not longer than CMD_STRING_LENGTH */ if (longestLineLength >= CMD_STRING_LENGTH - 100) { MrBayesPrint ("%s A maximum of %d characters is allowed on a single line\n", spacer, CMD_STRING_LENGTH - 100); MrBayesPrint ("%s in a file. The longest line of the file %s\n", spacer, inputFileName); MrBayesPrint ("%s contains at least one line with %d characters.\n", spacer, longestLineLength); nErrors++; } # if defined (MPI_ENABLED) MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if (sumErrors > 0) { MrBayesPrint ("%s There was an error on at least one processor\n", spacer); goto errorExit; } # else if (nErrors > 0) goto errorExit; # endif /* allocate a string long enough to hold a line */ s = (char *)SafeMalloc((size_t) (longestLineLength * sizeof(char))); if (!s) { MrBayesPrint ("%s Problem allocating string for reading file\n", spacer); nErrors++; } # if defined (MPI_ENABLED) MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if (sumErrors > 0) { MrBayesPrint ("%s There was an error on at least one processor\n", spacer); goto errorExit; } # else if (nErrors > 0) goto errorExit; # endif /* close binary file */ SafeFclose (&fp); /* open text file */ if ((fp = OpenTextFileR(inputFileName)) == NULL) { nErrors++; } # if defined (MPI_ENABLED) MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if (sumErrors > 0) { MrBayesPrint ("%s There was an error on at least one processor\n", spacer); goto errorExit; } # else if (nErrors > 0) goto errorExit; # endif /* parse file, reading each line in turn */ MrBayesPrint ("%s Parsing file\n", spacer); inMrbayesBlock = inDataBlock = inForeignBlock = inSumtBlock = NO; foundNewLine = NO; expecting = Expecting(COMMAND); do { /* read in a new line into s */ i = 0; do { c = fgetc(fp); if (c == '\r' || c == '\n' || c == EOF) s[i++] = '\n'; else s[i++] = c; } while (s[i-1] != '\n'); s[i] = '\0'; foundNewLine = YES; /* process string if not empty */ if (strlen(s) > 1) { /* check that all characters in the string are valid */ if (CheckStringValidity (s) == ERROR) { nErrors++; } # if defined (MPI_ENABLED) MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if (sumErrors > 0) { MrBayesPrint ("%s There was an error on at least one processor\n", spacer); goto errorExit; } # else if (nErrors > 0) goto errorExit; # endif /* interpret commands on line */ rc = ParseCommand (s); if (rc == ERROR) nErrors++; # if defined (MPI_ENABLED) MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if (sumErrors > 0) { MrBayesPrint ("%s There was an error on at least one processor\n", spacer); goto errorExit; } # else if (nErrors > 0) goto errorExit; # endif if (rc == NO_ERROR_QUIT) nErrors++; # if defined (MPI_ENABLED) MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if (sumErrors > 0) goto quitExit; # else if (nErrors > 0) goto quitExit; # endif } } while (c != EOF); MrBayesPrint ("%sReached end of file\n", spacer); if (inComment == YES) nErrors++; # if defined (MPI_ENABLED) MPI_Allreduce (&nErrors, &sumErrors, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if (sumErrors > 0) { MrBayesPrint ("%s There was an error on at least one processor\n", spacer); goto errorExit; } # else if (nErrors > 0) goto errorExit; # endif if (s) free (s); SafeFclose (&fp); numOpenExeFiles--; if (numOpenExeFiles > 0) { inMrbayesBlock = YES; MrBayesPrint ("\n Returning execution to calling file ...\n"); strcpy (spacer, " "); } else strcpy (spacer, ""); return (NO_ERROR); quitExit: if (s) free (s); SafeFclose (&fp); numOpenExeFiles--; if (numOpenExeFiles > 0) { inMrbayesBlock = YES; strcpy (spacer, " "); } else strcpy (spacer, ""); return (NO_ERROR_QUIT); errorExit: if (s) free (s); SafeFclose (&fp); numOpenExeFiles--; /* we increase the value above even if no file is successfully opened */ if (inComment == YES) { MrBayesPrint ("%s ERROR: Reached end of file while in comment.\n", spacer); inComment = NO; numComments = 0; } if (numOpenExeFiles > 0) { inMrbayesBlock = YES; MrBayesPrint ("\n Returning execution to calling file ...\n"); strcpy (spacer, " "); return (NO_ERROR); } else strcpy (spacer, ""); strcpy (token, "Execute"); i = 0; if (FindValidCommand (token, &i) == ERROR) MrBayesPrint ("%s Could not find execute\n", spacer); return (ERROR); } int DoExecuteParm (char *parmName, char *tkn) { strcpy (inputFileName, tkn); expecting = Expecting (SEMICOLON); return (NO_ERROR); MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */ } int DoExclude (void) { int i, alreadyDone; MrBayesPrint ("%s Excluding character(s)\n", spacer); /* add set to tempSet */ if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } /* merge tempSet with charset */ alreadyDone = NO; for (i=0; i numChar) { MrBayesPrint ("%s Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar); return (ERROR); } tempInt--; if (foundDash == YES) { if (fromI >= 0) toJ = tempInt; else { MrBayesPrint ("%s Improperly formatted exclude set\n", spacer); return (ERROR); } foundDash = NO; } else if (foundSlash == YES) { tempInt++; if (tempInt <= 1) { MrBayesPrint ("%s Improperly formatted exclude set\n", spacer); return (ERROR); } if (fromI >= 0 && toJ >= 0 && fromI < toJ) everyK = tempInt; else { MrBayesPrint ("%s Improperly formatted exclude set\n", spacer); return (ERROR); } foundSlash = NO; } else { if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; } else if (fromI < 0 && toJ < 0) { fromI = tempInt; } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else { MrBayesPrint ("%s Improperly formatted exclude set\n", spacer); { return (ERROR); } } } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(SEMICOLON); expecting |= Expecting(DASH); expecting |= Expecting(BACKSLASH); } else if (expecting == Expecting(DASH)) { foundDash = YES; expecting = Expecting(NUMBER); } else if (expecting == Expecting(BACKSLASH)) { foundSlash = YES; expecting = Expecting(NUMBER); } else return (ERROR); return (NO_ERROR); MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */ } int DoFormat (void) { int howMany, nDivs; if (inDataBlock == NO) { MrBayesPrint ("%s Formats can only be defined in a data block\n", spacer); return (ERROR); } if (CheckInitialPartitions() == ERROR) return (ERROR); /* enter name of default partition */ if (AddToString ("Default", partitionNames, &howMany) == ERROR) { MrBayesPrint ("%s Problem adding Default name to partition list\n", spacer); return (ERROR); } numDefinedPartitions = 1; nDivs = SetPartitionInfo (0); numCurrentDivisions = nDivs; if (nDivs == 1) MrBayesPrint ("%s Setting default partition (does not divide up characters).\n", spacer); else MrBayesPrint ("%s Setting default partition, dividing characters into %d parts.\n", spacer, nDivs); return (NO_ERROR); } int DoFormatParm (char *parmName, char *tkn) { int i, tempInt; char tempStr[100]; if (inDataBlock == NO) { MrBayesPrint ("%s Formats can only be defined in a data block\n", spacer); return (ERROR); } if (defTaxa == NO || defChars == NO) { MrBayesPrint ("%s The dimensions of the matrix must be defined before the format\n", spacer); return (ERROR); } if (expecting == Expecting(PARAMETER)) { expecting = Expecting(EQUALSIGN); if (!strcmp(parmName, "Interleave")) { expecting = Expecting(EQUALSIGN) | Expecting(PARAMETER) | Expecting(SEMICOLON); isInterleaved = YES; } } else { /* set Datatype (dataType) ************************************************************/ if (!strcmp(parmName, "Datatype")) { if (expecting == Expecting(EQUALSIGN)) expecting = Expecting(ALPHA); else if (expecting == Expecting(ALPHA)) { if (IsArgValid(tkn, tempStr) == NO_ERROR) { if (isMixed == NO) { if (!strcmp(tempStr, "Dna")) dataType = DNA; else if (!strcmp(tempStr, "Rna")) dataType = RNA; else if (!strcmp(tempStr, "Protein")) dataType = PROTEIN; else if (!strcmp(tempStr, "Restriction")) dataType = RESTRICTION; else if (!strcmp(tempStr, "Standard")) dataType = STANDARD; else if (!strcmp(tempStr, "Continuous")) dataType = CONTINUOUS; else if (!strcmp(tempStr, "Mixed")) { dataType = MIXED; isMixed = YES; for (i=0; i numChar) { MrBayesPrint ("%s Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar); return (ERROR); } tempInt--; if (foundDash == YES) { if (fromI >= 0) toJ = tempInt; else { MrBayesPrint ("%s Improperly formatted partition\n", spacer); return (ERROR); } foundDash = NO; } else if (foundSlash == YES) { tempInt++; if (tempInt <= 1) { MrBayesPrint ("%s Improperly formatted partition\n", spacer); return (ERROR); } if (fromI >= 0 && toJ >= 0 && fromI < toJ) everyK = tempInt; else { MrBayesPrint ("%s Improperly formatted partition\n", spacer); return (ERROR); } foundSlash = NO; } else { if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, numPartitions+1) == ERROR) return (ERROR); fromI = tempInt; } else if (fromI < 0 && toJ < 0) { fromI = tempInt; } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, numPartitions+1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, numPartitions+1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else { MrBayesPrint ("%s Improperly formatted partition\n", spacer); { return (ERROR); } } } expecting = Expecting(NUMBER); expecting |= Expecting(DASH); expecting |= Expecting(BACKSLASH); expecting |= Expecting(COMMA); expecting |= Expecting(RIGHTPAR); } else if (expecting == Expecting(DASH)) { foundDash = YES; expecting = Expecting(NUMBER); } else if (expecting == Expecting(BACKSLASH)) { foundSlash = YES; expecting = Expecting(NUMBER); } else if (expecting == Expecting(COMMA)) { /* add set to tempSet */ if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, numPartitions+1) == ERROR) { if (RemoveLastFromString (charSetNames) == ERROR) return (ERROR); return (ERROR); } } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, numPartitions+1) == ERROR) { if (RemoveLastFromString (charSetNames) == ERROR) return (ERROR); return (ERROR); } } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, numPartitions+1) == ERROR) { if (RemoveLastFromString (charSetNames) == ERROR) return (ERROR); return (ERROR); } } for (i=0; i= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, numPartitions+1) == ERROR) { if (RemoveLastFromString (charSetNames) == ERROR) return (ERROR); return (ERROR); } } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, numPartitions+1) == ERROR) { if (RemoveLastFromString (charSetNames) == ERROR) return (ERROR); return (ERROR); } } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, numPartitions+1) == ERROR) { if (RemoveLastFromString (charSetNames) == ERROR) return (ERROR); return (ERROR); } } /* merge tempSet */ for (i=0; i 1) MrBayesPrint ("%s There are a total of %d default data divisions\n", spacer, numPartitions); expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } /* set Interleave (isInterleaved) *****************************************************/ else if (!strcmp(parmName, "Interleave")) { if (expecting == Expecting(EQUALSIGN)) expecting = Expecting(ALPHA); else if (expecting == Expecting(ALPHA)) { if (IsArgValid(tkn, tempStr) == NO_ERROR) { if (!strcmp(tempStr, "Yes")) isInterleaved = YES; else isInterleaved = NO; } else { MrBayesPrint ("%s Invalid argument for interleaved data\n", spacer); return (ERROR); } if (isInterleaved == YES) MrBayesPrint ("%s Data matrix is interleaved\n", spacer); else MrBayesPrint ("%s Data matrix is not interleaved\n", spacer); expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } /* set Gap (gapId) ********************************************************************/ else if (!strcmp(parmName, "Gap")) { if (expecting == Expecting(EQUALSIGN)) { expecting = Expecting(ALPHA); expecting |= Expecting(QUESTIONMARK); expecting |= Expecting(DASH); expecting |= Expecting(NUMBER); expecting |= Expecting(ASTERISK); expecting |= Expecting(EXCLAMATIONMARK); expecting |= Expecting(PERCENT); expecting |= Expecting(WEIRD); } else if (((expecting & Expecting(ALPHA)) == Expecting(ALPHA)) || ((expecting & Expecting(QUESTIONMARK)) == Expecting(QUESTIONMARK)) || ((expecting & Expecting(DASH)) == Expecting(DASH)) || ((expecting & Expecting(NUMBER)) == Expecting(NUMBER)) || ((expecting & Expecting(ASTERISK)) == Expecting(ASTERISK)) || ((expecting & Expecting(EXCLAMATIONMARK)) == Expecting(EXCLAMATIONMARK)) || ((expecting & Expecting(PERCENT)) == Expecting(PERCENT)) || ((expecting & Expecting(WEIRD)) == Expecting(WEIRD))) { if (strlen(tkn) == 1) { if (tkn[0] == matchId || tkn[0] == missingId) { MrBayesPrint ("%s Gap character matches matching or missing characters\n", spacer); return (ERROR); } gapId = tkn[0]; } else { MrBayesPrint ("%s Invalid gap argument %s\n", spacer, tkn); return (ERROR); } MrBayesPrint ("%s Gaps coded as %s\n", spacer, tkn); expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } /* set Missing (missingId) ************************************************************/ else if (!strcmp(parmName, "Missing")) { if (expecting == Expecting(EQUALSIGN)) { expecting = Expecting(ALPHA); expecting |= Expecting(QUESTIONMARK); expecting |= Expecting(DASH); expecting |= Expecting(NUMBER); expecting |= Expecting(ASTERISK); expecting |= Expecting(EXCLAMATIONMARK); expecting |= Expecting(PERCENT); expecting |= Expecting(WEIRD); } else if (((expecting & Expecting(ALPHA)) == Expecting(ALPHA)) || ((expecting & Expecting(QUESTIONMARK)) == Expecting(QUESTIONMARK)) || ((expecting & Expecting(DASH)) == Expecting(DASH)) || ((expecting & Expecting(NUMBER)) == Expecting(NUMBER)) || ((expecting & Expecting(ASTERISK)) == Expecting(ASTERISK)) || ((expecting & Expecting(EXCLAMATIONMARK)) == Expecting(EXCLAMATIONMARK)) || ((expecting & Expecting(PERCENT)) == Expecting(PERCENT)) || ((expecting & Expecting(WEIRD)) == Expecting(WEIRD))) { if (strlen(tkn) == 1) { if (tkn[0] == gapId || tkn[0] == matchId) { MrBayesPrint ("%s Missing character matches matching or gap characters\n", spacer); return (ERROR); } missingId = tkn[0]; } else { MrBayesPrint ("%s Invalid missing argument %s\n", spacer, tkn); return (ERROR); } MrBayesPrint ("%s Missing data coded as %s\n", spacer, tkn); expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } /* set Matchchar (matchId) ************************************************************/ else if (!strcmp(parmName, "Matchchar")) { if (expecting == Expecting(EQUALSIGN)) { expecting = Expecting(ALPHA); expecting |= Expecting(QUESTIONMARK); expecting |= Expecting(DASH); expecting |= Expecting(NUMBER); expecting |= Expecting(ASTERISK); expecting |= Expecting(EXCLAMATIONMARK); expecting |= Expecting(PERCENT); expecting |= Expecting(WEIRD); } else if (((expecting & Expecting(ALPHA)) == Expecting(ALPHA)) || ((expecting & Expecting(QUESTIONMARK)) == Expecting(QUESTIONMARK)) || ((expecting & Expecting(DASH)) == Expecting(DASH)) || ((expecting & Expecting(NUMBER)) == Expecting(NUMBER)) || ((expecting & Expecting(ASTERISK)) == Expecting(ASTERISK)) || ((expecting & Expecting(EXCLAMATIONMARK)) == Expecting(EXCLAMATIONMARK)) || ((expecting & Expecting(PERCENT)) == Expecting(PERCENT)) || ((expecting & Expecting(WEIRD)) == Expecting(WEIRD))) { if (strlen(tkn) == 1) { if (tkn[0] == gapId || tkn[0] == missingId) { MrBayesPrint ("%s Matching character matches gap or missing characters\n", spacer); return (ERROR); } matchId = tkn[0]; } else { MrBayesPrint ("%s Invalid matchchar argument %s\n", spacer, tkn); return (ERROR); } MrBayesPrint ("%s Matching characters coded as %s\n", spacer, tkn); expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } else return (ERROR); } return (NO_ERROR); } int DoHelp (void) { int i, j, longestDescription; CmdType *p; if (foundFirst == NO) { longestDescription = 0; for (i=1; istring) > longestDescription) longestDescription = (int) strlen(p->string); } MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Commands that are available from the command \n"); MrBayesPrint (" line or from a MrBayes block include: \n"); MrBayesPrint (" \n"); for (i=1; icmdUse == IN_CMD && p->hiding == SHOW) { MrBayesPrint (" %s", p->string); for (j=0; jstring); j++) MrBayesPrint (" "); MrBayesPrint (" -- %s\n", p->cmdDescription); } } MrBayesPrint (" \n"); MrBayesPrint (" Commands that should be in a NEXUS file (data \n"); MrBayesPrint (" block or trees block) include: \n"); MrBayesPrint (" \n"); for (i=1; icmdUse == IN_FILE && p->hiding == SHOW) { MrBayesPrint (" %s", p->string); for (j=0; jstring); j++) MrBayesPrint (" "); MrBayesPrint (" -- %s\n", p->cmdDescription); } } MrBayesPrint (" \n"); MrBayesPrint (" Note that this program supports the use of the shortest unambiguous \n"); MrBayesPrint (" spelling of the above commands (e.g., \"exe\" instead of \"execute\"). \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } foundFirst = NO; return (NO_ERROR); } int DoHelpParm (char *parmName, char *tkn) { int i, j, tkLen, targetLen, numDiff, numMatches; CmdType *p, *q=NULL; if (expecting == Expecting(ALPHA)) { p = commands + 0; tkLen = (int) strlen(tkn); numMatches = 0; for (i=0; istring); if (tkLen <= targetLen) { for (j=0, numDiff=0; jstring[j])) numDiff++; } if (numDiff == 0) { numMatches++; q = p; if (tkLen == targetLen) break; } } p++; } if (numMatches == 0) { MrBayesPrint ("%s Could not find command \"%s\"\n", spacer, tkn); return (ERROR); } else if (numMatches == 1) { if (GetUserHelp (q->string) == ERROR) { MrBayesPrint ("%s Problem getting help for command \"%s\"\n", spacer, q->string); } } else { MrBayesPrint ("%s Ambiguous command \"%s\"\n", spacer, tkn); return (ERROR); } expecting = Expecting(SEMICOLON); foundFirst = YES; } else return (ERROR); return (NO_ERROR); MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */ } int DoInclude (void) { int i, alreadyDone; MrBayesPrint ("%s Including character(s)\n", spacer); /* add set to tempSet */ if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } /* merge tempSet with excludedChars */ alreadyDone = NO; for (i=0; i numChar) { MrBayesPrint ("%s Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar); return (ERROR); } tempInt--; if (foundDash == YES) { if (fromI >= 0) toJ = tempInt; else { MrBayesPrint ("%s Improperly formatted include set\n", spacer); return (ERROR); } foundDash = NO; } else if (foundSlash == YES) { tempInt++; if (tempInt <= 1) { MrBayesPrint ("%s Improperly formatted include set\n", spacer); return (ERROR); } if (fromI >= 0 && toJ >= 0 && fromI < toJ) everyK = tempInt; else { MrBayesPrint ("%s Improperly formatted include set\n", spacer); return (ERROR); } foundSlash = NO; } else { if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; } else if (fromI < 0 && toJ < 0) { fromI = tempInt; } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else { MrBayesPrint ("%s Improperly formatted include set\n", spacer); { return (ERROR); } } } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(SEMICOLON); expecting |= Expecting(DASH); expecting |= Expecting(BACKSLASH); } else if (expecting == Expecting(DASH)) { foundDash = YES; expecting = Expecting(NUMBER); } else if (expecting == Expecting(BACKSLASH)) { foundSlash = YES; expecting = Expecting(NUMBER); } else return (ERROR); return (NO_ERROR); MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */ } int DoLog (void) { if (logToFile == YES) { SafeFclose (&logFileFp); if (replaceLogFile == YES) { if ((logFileFp = fopen (logFileName, "w")) == NULL) { MrBayesPrint ("%s Could not open log file \"%s\"\n", spacer, logFileName); logToFile = NO; return (ERROR); } } else { if ((logFileFp = fopen (logFileName, "a")) == NULL) { MrBayesPrint ("%s Could not open log file \"%s\"\n", spacer, logFileName); logToFile = NO; return (ERROR); } } MrBayesPrint ("%s Logging screen output to file \"%s\"\n", spacer, logFileName); } else { SafeFclose (&logFileFp); MrBayesPrint ("%s Terminating log output\n", spacer); } return (NO_ERROR); } int DoLogParm (char *parmName, char *tkn) { if (expecting == Expecting(PARAMETER)) { if (!strcmp(parmName, "Start")) { if (logToFile == YES) MrBayesPrint ("%s Logging to file is already on\n", spacer, logFileName); else logToFile = YES; expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else if (!strcmp(parmName, "Stop")) { if (logToFile == NO) MrBayesPrint ("%s Logging to file is already off\n", spacer, logFileName); else logToFile = NO; expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else if (!strcmp(parmName, "Replace")) { replaceLogFile = YES; expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else if (!strcmp(parmName, "Append")) { replaceLogFile = NO; expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else expecting = Expecting(EQUALSIGN); } else { if (!strcmp(parmName, "Filename")) { if (expecting == Expecting(EQUALSIGN)) { expecting = Expecting(ALPHA); readWord = YES; } else if (expecting == Expecting(ALPHA)) { strcpy (logFileName, tkn); expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } else { MrBayesPrint ("%s Unknown parameter in Log\n", spacer); return (ERROR); } } return (NO_ERROR); } int DoManual (void) { int i, j, logSetting; char title[100]; FILE *fp, *logfp; CmdType *p; /* try to open file, return error if present */ if ((fp = fopen(manFileName,"r")) != NULL) { MrBayesPrint ("%s File \"%s\" already exists \n", spacer, manFileName); SafeFclose(&fp); return (ERROR); } /* try to open file for writing, return error if not possible */ if ((fp = fopen(manFileName,"w")) == NULL) { MrBayesPrint ("%s Could not open file for writing\n", spacer, manFileName); return (ERROR); } /* print message */ MrBayesPrint ("%s Producing command reference file \"%s\"\n", spacer, manFileName); /* temporarily disable normal logging and switch echoing off */ logSetting = logToFile; logfp = logFileFp; echoMB = NO; logToFile = YES; logFileFp = fp; /* produce command reference file */ /* header */ strcpy (title, "Command Reference for MrBayes ver. "); strcat (title, VERSION_NUMBER); i = (70 - (int) strlen (title)) / 2; j = 70 - i - (int) strlen(title); MrBayesPrint (" \n"); MrBayesPrint (" \n"); MrBayesPrint (" \n"); MrBayesPrint (" \n"); MrBayesPrint (" %*c%s%*c \n", i, ' ', title, j, ' '); MrBayesPrint (" \n"); MrBayesPrint (" (c) John P. Huelsenbeck and Fredrik Ronquist \n"); MrBayesPrint (" \n"); MrBayesPrint (" \n"); /* summary */ MrBayesPrint (" \n"); MrBayesPrint (" *************************************************************************** \n"); MrBayesPrint (" * * \n"); MrBayesPrint (" * 1. Command summary * \n"); MrBayesPrint (" * * \n"); MrBayesPrint (" *************************************************************************** \n"); MrBayesPrint (" \n"); foundFirst = NO; if (DoHelp() == ERROR) { MrBayesPrint ("%s Could not produce command reference summary\n", spacer); goto errorExit; } /* list of MrBayes commands */ MrBayesPrint (" \n"); MrBayesPrint (" *************************************************************************** \n"); MrBayesPrint (" * * \n"); MrBayesPrint (" * 2. MrBayes commands * \n"); MrBayesPrint (" * * \n"); MrBayesPrint (" *************************************************************************** \n"); MrBayesPrint (" \n"); for (i=1; icmdUse == IN_CMD && p->hiding == SHOW) { if (GetUserHelp(p->string)==ERROR) goto errorExit; } } /* list of data or tree block commands */ MrBayesPrint (" \n"); MrBayesPrint (" *************************************************************************** \n"); MrBayesPrint (" * * \n"); MrBayesPrint (" * 3. 'Data' or 'tree' block commands (in #NEXUS file) * \n"); MrBayesPrint (" * * \n"); MrBayesPrint (" *************************************************************************** \n"); MrBayesPrint (" \n"); for (i=1; icmdUse == IN_FILE && p->hiding == SHOW) { if (GetUserHelp(p->string) == ERROR) goto errorExit; } } /* return logging to previous setings and switch echoing on */ SafeFclose (&fp); logToFile = logSetting; logFileFp = logfp; echoMB = YES; MrBayesPrint ("%s Successfully produced command reference file \"%s\"\n", spacer, manFileName); return (NO_ERROR); errorExit: SafeFclose (&fp); logToFile = logSetting; logFileFp = logfp; echoMB = YES; return (ERROR); } int DoManualParm (char *parmName, char *tkn) { if (expecting == Expecting(PARAMETER)) { expecting = Expecting(EQUALSIGN); } else { if (!strcmp(parmName, "Filename")) { if (expecting == Expecting(EQUALSIGN)) { expecting = Expecting(ALPHA); readWord = YES; } else if (expecting == Expecting(ALPHA)) { strcpy (manFileName, tkn); expecting = Expecting(SEMICOLON); } else return (ERROR); } else { MrBayesPrint ("%s Unknown parameter in Manual\n", spacer); return (ERROR); } } return (NO_ERROR); } int DoMatrix (void) { int i, j, hasMissingAmbig; if (taxonCount != numTaxa) { MrBayesPrint ("%s Problem with number of taxa read in (%d taxa read in, while expecting %d)\n", spacer, taxonCount, numTaxa); FreeMatrix(); return (ERROR); } for (i=0; i 1) */ sprintf (comptreeParams.comptFileName1, "%s.run1.t", inputFileName); strcpy (comptreeParams.comptFileName2, comptreeParams.comptFileName1); if (chainParams.numRuns == 1) sprintf (plotParams.plotFileName, "%s.p", inputFileName); else /* if (chainParams.numRuns > 1) */ sprintf (plotParams.plotFileName, "%s.run1.p", inputFileName); strcpy (chainParams.chainFileName, inputFileName); if (chainParams.numRuns > 1) MrBayesPrint ("%s Setting output file names to \"%s.run.

\"\n", spacer, chainParams.chainFileName); else MrBayesPrint ("%s Setting output file names to \"%s.

\"\n", spacer, chainParams.chainFileName); MrBayesPrint ("%s Successfully read matrix\n", spacer); if (matrixHasPoly == YES) MrBayesPrint ("%s Matrix contains polymorphisms, interpreted as ambiguity\n", spacer); defMatrix = YES; # if 0 for (i=0; i 0) { if (taxaInfo[taxonCount-1].charCount < numChar) foundNewLine = NO; } } if (taxonCount >= numTaxa && foundNewLine == YES) { if (isInterleaved == YES) { taxonCount = 0; isFirstInterleavedBlock = NO; } else { MrBayesPrint ("%s Too many taxa in matrix\n", spacer); goto errorExit; } } if (taxaInfo[0].charCount > 4010) i = 1; if (foundNewLine == YES) { /* Should be a taxon. */ if (isFirstInterleavedBlock == YES) { /* If this is the first interleaved block, then we need to add the taxon to the string of taxon names. */ if (AddToString (tkn, taxaNames, &howMany) == ERROR) { MrBayesPrint ("%s Problem adding taxon %s to list\n", spacer, tkn); goto errorExit; } if (howMany - 1 != taxonCount) { MrBayesPrint ("%s Problem adding taxon %s to list\n", spacer, tkn); goto errorExit; } if (numTaxa < 10) MrBayesPrint ("%s Taxon %d -> %s\n", spacer, taxonCount+1, tkn); else if (numTaxa < 100 && numTaxa >= 10) MrBayesPrint ("%s Taxon %2d -> %s\n", spacer, taxonCount+1, tkn); else if (numTaxa < 1000 && numTaxa >= 100) MrBayesPrint ("%s Taxon %3d -> %s\n", spacer, taxonCount+1, tkn); else MrBayesPrint ("%s Taxon %4d -> %s\n", spacer, taxonCount+1, tkn); } else { /* If this is not the first interleaved block, then we need to check to see if taxon name is present and in correct place. */ if (CheckString (tkn, taxaNames, &howMany) == ERROR) { MrBayesPrint ("%s Could not find taxon %s in list of taxa\n", spacer, tkn); goto errorExit; } if (howMany - 1 != taxonCount) { MrBayesPrint ("%s Could not find taxon %s in correct position in list of taxa\n", spacer, tkn); goto errorExit; } } foundNewLine = NO; isNegative = NO; taxonCount++; } else { /* Should be a character (either continuous or otherwise). */ if (charInfo[taxaInfo[taxonCount-1].charCount].charType == CONTINUOUS) { /* If we have a CONTINUOUS character, then the entire token should either be a number or a dash (for a negative sign). */ if (!strcmp(tkn, "-")) { /* Dealing with a negative number. We will multiply the next tkn, which had better be a number, by -1. */ isNegative = YES; } else { /* We have a number, we hope. */ if (tkn[0] == matchId) { /* If the token is a matchchar, then things are simple. */ if (taxonCount == 1) { MrBayesPrint ("%s Matching characters cannot be in first taxon\n", spacer); goto errorExit; } charCode = matrix[pos(0,taxaInfo[taxonCount-1].charCount,numChar)]; matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount,numChar)] = charCode; } else { /* Otherwise, we have a number. Check that it is a valid number first... */ if (!IsIn(tkn[0],"0123456789.")) { MrBayesPrint ("%s Expecting a number for the continuous character\n", spacer); goto errorExit; } /* ... and then put the character into the matrix. Note that matrix is defined as an integer, but we may have floating precision continuous characters. To get around this, we multiply the value of the character by 1000 before putting it into matrix. We will divide by 1000 later on when/if we use the characters. */ sscanf (tkn, "%lf", &charValue); charValue *= 1000.0; if (isNegative == YES) { charValue *= -1.0; isNegative = NO; } /*MrBayesPrint ("%d \n", (int)charValue);*/ matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = (int)charValue; } } } else { /* Otherwise, we are dealing with a run-of-the-mill character, and we cannot expect the entire token to contain only a single character. We must, therefore, go through the token character-by-character. */ i = 0; while (tkn[i] != '\0') { /*MrBayesPrint ("%c", tkn[i]);*/ if (tkn[i] == matchId) { if (taxonCount == 1) { MrBayesPrint ("%s Matching characters cannot be in first taxon\n", spacer); goto errorExit; } charCode = matrix[pos(0,taxaInfo[taxonCount-1].charCount,numChar)]; matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = charCode; } else { if ((tkn[i] == ')' && isInAmbig == YES) || (tkn[i] == '}' && isInPoly == YES)) { isInAmbig = isInPoly = NO; charCode = theAmbigChar; j = CharacterNumber (charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType); if (j > charInfo[taxaInfo[taxonCount-1].charCount].numStates) charInfo[taxaInfo[taxonCount-1].charCount].numStates = j; matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = charCode; theAmbigChar = 0; } else if ((tkn[i] == '(' && isInAmbig == YES) || (tkn[i] == '{' && isInPoly == YES)) { if (isInAmbig == YES) MrBayesPrint ("%s Found an inappropriate \"(\"\n", spacer); else MrBayesPrint ("%s Found an inappropriate \"{\"\n", spacer); goto errorExit; } else if (isInAmbig == YES || isInPoly == YES) { if (tkn[i] == ',') expecting |= Expecting (COMMA); else { if (CharacterCode(tkn[i], &charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType) == ERROR) goto errorExit; if (charCode == MISSING || charCode == GAP) goto errorExit; theAmbigChar |= charCode; expecting ^= Expecting (COMMA); } } else if (tkn[i] == '{' && isInPoly == NO && isInAmbig == NO) { isInPoly = YES; matrixHasPoly = YES; theAmbigChar = 0; } else if (tkn[i] == '(' && isInPoly == NO && isInAmbig == NO) { isInAmbig = YES; theAmbigChar = 0; } else if (tkn[i] == '(' && isInPoly == NO && isInAmbig == NO) { isInAmbig = YES; theAmbigChar = 0; } else { if (CharacterCode(tkn[i], &charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType) == ERROR) { MrBayesPrint ("%s Error while reading character position %d (charCode %d)\n", spacer, taxaInfo[taxonCount-1].charCount, charCode); goto errorExit; } if (charCode != MISSING && charCode != GAP) { j = CharacterNumber (charCode, charInfo[taxaInfo[taxonCount-1].charCount].charType); if (j > charInfo[taxaInfo[taxonCount-1].charCount].numStates) charInfo[taxaInfo[taxonCount-1].charCount].numStates = j; } matrix[pos(taxonCount-1,taxaInfo[taxonCount-1].charCount++,numChar)] = charCode; } } i++; } } } return (NO_ERROR); MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */ errorExit: FreeMatrix(); return (ERROR); } int DoNexusParm (char *parmName, char *tkn) { if (!strcmp(parmName, "NEXUS")) { MrBayesPrint ("%s Expecting NEXUS formatted file\n", spacer); expecting = Expecting(COMMAND); } else { MrBayesPrint ("%s Found %s\n", spacer, tkn); return (ERROR); } return (NO_ERROR); } int DoOutgroup (void) { char tempName[100]; if (GetNameFromString (taxaNames, tempName, outGroupNum + 1) == ERROR) { MrBayesPrint ("%s Error getting taxon names \n", spacer); return (ERROR); } MrBayesPrint ("%s Setting outgroup to taxon \"%s\"\n", spacer, tempName); if (isUserTreeDefined == YES && userTree->isRooted == NO) { MoveCalculationRoot (userTree, outGroupNum); } return (NO_ERROR); } int DoOutgroupParm (char *parmName, char *tkn) { int howMany, tempInt; if (expecting == Expecting(ALPHA)) { if (CheckString (tkn, taxaNames, &howMany) == ERROR) { MrBayesPrint ("%s Could not find taxon %s in list of taxa\n", spacer, tkn); return (ERROR); } outGroupNum = howMany - 1; expecting = Expecting(SEMICOLON); } else if (expecting == Expecting(NUMBER)) { if (CheckString (tkn, taxaNames, &howMany) == ERROR) { /* OK, as we expect, the taxon is not a digit. So, now we assume that the user is assigning the outgroup by its number */ sscanf (tkn, "%d", &tempInt); if (tempInt < 1 || tempInt > numTaxa) { MrBayesPrint ("%s Taxon number %d is out of range\n", spacer, tempInt); return (ERROR); } outGroupNum = tempInt - 1; } else { outGroupNum = howMany - 1; } expecting = Expecting(SEMICOLON); } else return (ERROR); return (NO_ERROR); MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */ } int DoPairs (void) { MrBayesPrint ("\n"); MrBayesPrint ("%s Successfully defined character pairings\n", spacer); defPairs = YES; foundFirst = NO; return (NO_ERROR); } int DoPairsParm (char *parmName, char *tkn) { int i, tempInt; if (defMatrix == NO) { MrBayesPrint ("%s A matrix must be specified before you can define pairs of characters\n", spacer); return (ERROR); } if (defPairs == YES) { MrBayesPrint ("%s Character pairs have been previously defined \n", spacer); MrBayesPrint ("%s Now overwriting old pairings\n", spacer); for (i=0; i numChar) { MrBayesPrint ("\n"); MrBayesPrint ("%s Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar); for (i=0; i= 0) if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR) return (ERROR); /* add temporary information to partition */ for (i=0; i 99) { MrBayesPrint ("%s Partition name is too long\n", spacer); return (ERROR); } /* check to see if the name has already been used as a partition */ if (numDefinedPartitions > 1) { if (CheckString (tkn, partitionNames, &howMany) == ERROR) { /* if the partition name has not been used, then we should have an ERROR returned */ /* we _want_ to be here */ } else { MrBayesPrint ("%s Partition name '%s' has been used previously\n", spacer, tkn); return (ERROR); } } else if (numDefinedPartitions > MAX_NUM_PARTITIONS) { MrBayesPrint ("%s You cannot define more than %d partitions\n", spacer, MAX_NUM_PARTITIONS); return (ERROR); } /* add the name temporarily to tempSetName */ strcpy (tempSetName, tkn); /* clear tempSet */ for (i=0; i numChar) { MrBayesPrint ("%s Character number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numChar); return (ERROR); } tempInt--; if (foundDash == YES) { if (fromI >= 0) toJ = tempInt; else { MrBayesPrint ("%s Improperly formatted partition\n", spacer); return (ERROR); } foundDash = NO; } else if (foundSlash == YES) { tempInt++; if (tempInt <= 1) { MrBayesPrint ("%s Improperly formatted charset\n", spacer); return (ERROR); } if (fromI >= 0 && toJ >= 0 && fromI < toJ) everyK = tempInt; else { MrBayesPrint ("%s Improperly formatted charset\n", spacer); return (ERROR); } foundSlash = NO; } else { if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR) return (ERROR); fromI = tempInt; } else if (fromI < 0 && toJ < 0) { fromI = tempInt; } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else { MrBayesPrint ("%s Improperly formatted charset\n", spacer); { return (ERROR); } } } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(SEMICOLON); expecting |= Expecting(DASH); expecting |= Expecting(BACKSLASH); expecting |= Expecting(COMMA); } } else if (expecting == Expecting(COMMA)) { /* add set to tempSet */ if (fromI >= 0) if (AddToSet (fromI, toJ, everyK, whichPartition+1) == ERROR) return (ERROR); fromI = toJ = everyK = -1; foundDash = foundSlash = NO; whichPartition++; if (whichPartition > numPartitions) { MrBayesPrint ("%s Too many partitions of the data (expecting %d)\n", spacer, numPartitions); return (ERROR); } expecting = Expecting(NUMBER); expecting |= Expecting(ALPHA); } else if (expecting == Expecting(COLON)) { expecting = Expecting(NUMBER); expecting |= Expecting(ALPHA); } else if (expecting == Expecting(DASH)) { foundDash = YES; expecting = Expecting(NUMBER); } else if (expecting == Expecting(BACKSLASH)) { foundSlash = YES; expecting = Expecting(NUMBER); } else return (ERROR); return (NO_ERROR); } int DoProps (void) { int i, j, j1, j2, k, index, whichParamToChange, invalidProp; MrBFlt tempD; char tempString[100]; MoveType *mt = NULL; for (j2=0;j2<10;j2++) { /* display options */ MrBayesPrint ("%s Available proposal mechanisms:\n\n", spacer); for (i=index=0; ilevel) continue; MrBayesPrint ("%s %2d -- Change %s\n", spacer, ++index, mt->name); MrBayesPrint ("%s proposal rate: %1.3lf\n", spacer, mt->relProposalProb); for (j=0; jnumTuningParams; j++) MrBayesPrint ("%s %s: %1.3lf\n", spacer, mt->nameTuning[j], mt->tuningParam[j]); } MrBayesPrint ("\n"); /* pick an option */ for (j1=0; j1<10; j1++) { MrBayesPrint ("%s Select a parameter to change (1 - %d; 0 to exit; %d to zero all proposal rates): ", spacer, index, index + 1); fgets (tempString, 100, stdin); sscanf (tempString, "%d", &whichParamToChange); if (whichParamToChange >= 0 && whichParamToChange <= index + 1) break; } if (whichParamToChange == 0) { /* exit */ MrBayesPrint ("%s Exit props\n", spacer); return (NO_ERROR); } else if (whichParamToChange == index + 1) { /* zero all proposal rates */ MrBayesPrint ("%s Setting all proposal rates to zero (this is very dangerous)\n", spacer); for (i=0; i= mt->level) mt->relProposalProb = 0.0; } } else if (whichParamToChange > 0 && whichParamToChange <= index) { /* find the proposal to change */ for (i=index=0; ilevel) continue; if (++index == whichParamToChange) break; } /* change the parameters for the proposal mechanism */ MrBayesPrint ("%s Proposal %d: Change %s\n", spacer, whichParamToChange, mt->name); for (j1=0; j1<10; j1++) { invalidProp = NO; MrBayesPrint ("%s New proposal rate ( to keep old = %1.3lf): ", spacer, mt->relProposalProb); fgets (tempString, 100, stdin); k = sscanf (tempString, "%lf", &tempD); if (k == 1 && tempD > 0.0 && tempD < 1000.0) mt->relProposalProb = tempD; else if (k != EOF) invalidProp = YES; if (invalidProp == YES) MrBayesPrint ("%s Incorrect value...try again\n", spacer); else break; } for (j=0; jnumTuningParams; j++) { for (j1=0; j1<10; j1++) { invalidProp = NO; MrBayesPrint ("%s New %s ( to keep old = %1.3lf): ", spacer, mt->nameTuning[j], mt->tuningParam[j]); fgets (tempString, 100, stdin); k = sscanf (tempString, "%lf", &tempD); if (k == 1 && tempD >= mt->minimum[j] && tempD <= mt->maximum[j]) mt->tuningParam[j] = tempD; else if (k != EOF) invalidProp = YES; if (invalidProp == YES) MrBayesPrint ("%s Incorrect value...try again\n", spacer); else break; } } } else MrBayesPrint ("%s Too many invalid entries\n", spacer); } return (NO_ERROR); } int DoRestore (void) { int i, alreadyDone; MrBayesPrint ("%s Restore taxa\n", spacer); /* add set to tempSet */ if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } /* merge tempSet with excludedTaxa */ alreadyDone = NO; for (i=0; i= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } else if (fromI >= 0 && toJ >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); } tempSet[howMany-1] = 1; } fromI = toJ = everyK = -1; } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(SEMICOLON); } else if (expecting == Expecting(NUMBER)) { if (strlen(tkn) == 1 && !strcmp(tkn, ".")) { tempInt = numTaxa; } else { sscanf (tkn, "%d", &tempInt); if (tempInt <= 0 || tempInt > numTaxa) { MrBayesPrint ("%s Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa); return (ERROR); } } tempInt--; if (foundDash == YES) { if (fromI >= 0) toJ = tempInt; else { MrBayesPrint ("%s Improperly formatted restore set\n", spacer); return (ERROR); } foundDash = NO; } else { if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; } else if (fromI < 0 && toJ < 0) { fromI = tempInt; } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else { MrBayesPrint ("%s Improperly formatted restore set\n", spacer); { return (ERROR); } } } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(SEMICOLON); expecting |= Expecting(DASH); } else if (expecting == Expecting(DASH)) { foundDash = YES; expecting = Expecting(NUMBER); } else return (ERROR); return (NO_ERROR); MrBayesPrint ("%s", parmName); /* just because I am tired of seeing the unused parameter error msg */ } int DoRoot (void) { char tempName[100]; if (isUserTreeDefined == NO) { MrBayesPrint (" No tree in memory\n", spacer); return (ERROR); } if (userTree->isRooted == NO) { if (RootTree (userTree) == ERROR) return (ERROR); GetNameFromString (taxaNames, tempName, outGroupNum); MrBayesPrint ("%s Rooting user tree midway between the outgroup (%s) and the ingroup\n", spacer, tempName); } else MrBayesPrint ("%s Tree is already rooted\n", spacer); return (NO_ERROR); } int DoSet (void) { return (NO_ERROR); } int DoSetParm (char *parmName, char *tkn) { int howMany, nDivs; char tempStr[100]; if (expecting == Expecting(PARAMETER)) { expecting = Expecting(EQUALSIGN); } else { /* set Autoclose (autoClose) **********************************************************/ if (!strcmp(parmName, "Autoclose")) { if (expecting == Expecting(EQUALSIGN)) expecting = Expecting(ALPHA); else if (expecting == Expecting(ALPHA)) { if (IsArgValid(tkn, tempStr) == NO_ERROR) { if (!strcmp(tempStr, "Yes")) autoClose = YES; else autoClose = NO; } else { MrBayesPrint ("%s Invalid argument for autoclose\n", spacer); return (ERROR); } if (autoClose == YES) MrBayesPrint ("%s Setting autoclose to yes\n", spacer); else MrBayesPrint ("%s Setting autoclose to no\n", spacer); expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } /* set Nowarnings (noWarn) **********************************************************/ else if (!strcmp(parmName, "Nowarnings")) { if (expecting == Expecting(EQUALSIGN)) expecting = Expecting(ALPHA); else if (expecting == Expecting(ALPHA)) { if (IsArgValid(tkn, tempStr) == NO_ERROR) { if (!strcmp(tempStr, "Yes")) noWarn = YES; else noWarn = NO; } else { MrBayesPrint ("%s Invalid argument for nowarnings\n", spacer); return (ERROR); } if (noWarn == YES) MrBayesPrint ("%s Setting nowarnings to yes\n", spacer); else MrBayesPrint ("%s Setting nowarnings to no\n", spacer); expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } /* set Quitonerror (quitOnError) **************************************************/ else if (!strcmp(parmName, "Mode")) { if (expecting == Expecting(EQUALSIGN)) expecting = Expecting(ALPHA); else if (expecting == Expecting(ALPHA)) { if (IsArgValid(tkn, tempStr) == NO_ERROR) { if (!strcmp(tempStr, "Yes")) quitOnError = YES; else quitOnError = NO; } else { MrBayesPrint ("%s Invalid argument for quitonerror\n", spacer); return (ERROR); } if (quitOnError == YES) MrBayesPrint ("%s Setting quitonerror to yes\n", spacer); else MrBayesPrint ("%s Setting quitonerror to no\n", spacer); expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } /* set AutoOverwrite (autoOverwrite) **************************************************/ else if (!strcmp(parmName, "Autooverwrite")) { if (expecting == Expecting(EQUALSIGN)) expecting = Expecting(ALPHA); else if (expecting == Expecting(ALPHA)) { if (IsArgValid(tkn, tempStr) == NO_ERROR) { if (!strcmp(tempStr, "Yes")) { autoOverwrite = YES; MrBayesPrint ("%s Setting autooverwrite to yes\n", spacer); } else { autoOverwrite = NO; MrBayesPrint ("%s Setting autooverwrite to no\n", spacer); } } else { MrBayesPrint ("%s Invalid argument for autooverwrite\n", spacer); return (ERROR); } expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } /* set Partition (partitionNum) *******************************************************/ else if (!strcmp(parmName, "Partition")) { if (defMatrix == NO) { MrBayesPrint ("%s A character matrix must be defined first\n", spacer); return (ERROR); } if (expecting == Expecting(EQUALSIGN)) expecting = Expecting(ALPHA) | Expecting(NUMBER); else if (expecting == Expecting(ALPHA)) { /* first check to see if name is there */ if (CheckString (tkn, partitionNames, &howMany) == ERROR) { MrBayesPrint ("%s Could not find \"%s\" as a defined partition\n", spacer, tkn); return (ERROR); } SetModelDefaults (); partitionNum = howMany; nDivs = SetPartitionInfo (howMany-1); numCurrentDivisions = nDivs; if (nDivs == 1) MrBayesPrint ("%s Setting %s as the partition (does not divide up characters).\n", spacer, tkn); else MrBayesPrint ("%s Setting %s as the partition, dividing characters into %d parts.\n", spacer, tkn, nDivs); MrBayesPrint ("%s Resetting model values to defaults (NB! Any existing model settings will be deleted!)\n", spacer); MrBayesPrint ("%s Reinitializing link table (linking all parameters)\n", spacer); if (InitializeLinks () == ERROR) { MrBayesPrint ("%s Problem initializing link table\n", spacer); return (ERROR); } expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else if (expecting == Expecting(NUMBER)) { sscanf (tkn, "%d", &howMany); if (howMany > numDefinedPartitions) { MrBayesPrint ("%s Partition number %d is not a valid parition. Only %d partitions\n", spacer, howMany, numDefinedPartitions); MrBayesPrint ("%s have been defined.\n", spacer); return (ERROR); } if (howMany < 1) { MrBayesPrint ("%s Partition number %d is not a valid parition. Must be between 1 and %d.\n", spacer, howMany, numDefinedPartitions); return (ERROR); } if (GetNameFromString (partitionNames, tempStr, howMany) == ERROR) { MrBayesPrint ("%s Could not find name for partition number %d.\n", spacer, howMany); return (ERROR); } SetModelDefaults (); partitionNum = howMany; nDivs = SetPartitionInfo (howMany-1); numCurrentDivisions = nDivs; if (nDivs == 1) MrBayesPrint ("%s Setting %s as the partition (does not divide up characters).\n", spacer, tempStr); else MrBayesPrint ("%s Setting %s as the partition, dividing characters into %d parts.\n", spacer, tempStr, nDivs); MrBayesPrint ("%s Resetting model values to defaults\n", spacer); MrBayesPrint ("%s Reinitializing link table (linking all parameters)\n", spacer); if (InitializeLinks () == ERROR) { MrBayesPrint ("%s Problem initializing link table\n", spacer); return (ERROR); } expecting = Expecting(PARAMETER) | Expecting(SEMICOLON); } else return (ERROR); } else return (ERROR); } return (NO_ERROR); } int DoShowMatrix (void) { int i, j, nameLen, start, finish, ct, longestName; char tempStr[100], stride; if (defMatrix == NO) { MrBayesPrint ("%s A character matrix must be defined first\n", spacer); return (ERROR); } longestName = 0; for (i=0; i longestName) longestName = nameLen; } stride = 50; start = finish = 0; do { finish += stride; if (finish > numChar) finish = numChar; MrBayesPrint ("%s ", spacer); for (j=0; j= longestName) { for (j=0; jisRooted == YES) MrBayesPrint ("\n Tree is rooted:\n\n"); else MrBayesPrint ("\n Tree is unrooted:\n\n"); if (ShowTree (userTree->root, userTree->isRooted, numTaxa) == ERROR) { return (ERROR); } else MrBayesPrint ("\n"); } else { MrBayesPrint ("%s A user tree has not been defined\n", spacer); } return (NO_ERROR); } int DoTaxaset (void) { int i, howMany; /* first add name to taxaSetName */ if (AddToString (tempSetName, taxaSetNames, &howMany) == ERROR) { MrBayesPrint ("%s Problem adding taxset %s to list\n", spacer, tempSetName); return (ERROR); } if (howMany != numTaxaSets + 1) { MrBayesPrint ("%s Problem adding taxset %s to list\n", spacer, tempSetName, numTaxaSets); if (RemoveLastFromString (taxaSetNames) == ERROR) return (ERROR); return (ERROR); } /* add set to tempSet */ if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) { if (RemoveLastFromString (taxaSetNames) == ERROR) return (ERROR); return (ERROR); } } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) { if (RemoveLastFromString (taxaSetNames) == ERROR) return (ERROR); return (ERROR); } } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) { if (RemoveLastFromString (taxaSetNames) == ERROR) return (ERROR); return (ERROR); } } /* merge tempSet with taxaSet */ for (i=0; i 99) { MrBayesPrint ("%s Taxset name is too long\n", spacer); return (ERROR); } /* check to see if the name has already been used as a taxset */ if (numTaxaSets > 0) { if (CheckString (tkn, taxaSetNames, &howMany) == ERROR) { /* if the taxset name has not been used, then we should have an ERROR returned */ /* we _want_ to be here */ } else { MrBayesPrint ("%s Taxset name has been used previously\n", spacer); return (ERROR); } } else if (numTaxaSets > 30) { MrBayesPrint ("%s You cannot define more than 30 taxsets\n", spacer); return (ERROR); } /* add the name to the taxa set */ strcpy (tempSetName, tkn); /* clear tempSet */ for (i=0; i numTaxa) { MrBayesPrint ("%s Taxon number %d is out of range (should be between %d and %d)\n", spacer, tempInt, 1, numTaxa); return (ERROR); } } tempInt--; if (foundDash == YES) { if (fromI >= 0) toJ = tempInt; else { MrBayesPrint ("%s Improperly formatted taxset\n", spacer); return (ERROR); } foundDash = NO; } else if (foundSlash == YES) { tempInt++; if (tempInt <= 1) { MrBayesPrint ("%s Improperly formatted taxset\n", spacer); return (ERROR); } if (fromI >= 0 && toJ >= 0 && fromI < toJ) everyK = tempInt; else { MrBayesPrint ("%s Improperly formatted taxset\n", spacer); return (ERROR); } foundSlash = NO; } else { if (fromI >= 0 && toJ < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; } else if (fromI < 0 && toJ < 0) { fromI = tempInt; } else if (fromI >= 0 && toJ >= 0 && everyK < 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else if (fromI >= 0 && toJ >= 0 && everyK >= 0) { if (AddToSet (fromI, toJ, everyK, 1) == ERROR) return (ERROR); fromI = tempInt; toJ = everyK = -1; } else { MrBayesPrint ("%s Improperly formatted taxset\n", spacer); { return (ERROR); } } } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(SEMICOLON); expecting |= Expecting(DASH); expecting |= Expecting(BACKSLASH); } else if (expecting == Expecting(DASH)) { foundDash = YES; expecting = Expecting(NUMBER); } else if (expecting == Expecting(BACKSLASH)) { foundSlash = YES; expecting = Expecting(NUMBER); } else return (ERROR); return (NO_ERROR); } int DoTaxaStat (void) { int i, j, maxLen, nameLen, nIncludedTaxa; char tempName[100]; if (defMatrix == NO) { MrBayesPrint ("%s A character matrix must be defined first\n", spacer); return (ERROR); } /* find maximum length of taxon name */ maxLen = nIncludedTaxa = 0; for (i=0; i maxLen) maxLen = (int) strlen(tempName); if (taxaInfo[i].isDeleted == NO) nIncludedTaxa++; } MrBayesPrint ("%s Showing taxon status:\n\n", spacer); if (nIncludedTaxa == numTaxa) MrBayesPrint ("%s Number of taxa = %d (all of which are included)\n", spacer, numTaxa); else MrBayesPrint ("%s Number of taxa = %d (of which %d are included)\n", spacer, numTaxa, nIncludedTaxa); MrBayesPrint ("%s Number of constraints = %d\n\n", spacer, numDefinedConstraints); if (numDefinedConstraints > 0) { for (j=0; j 0.0) { if (relConstraintProbs[j] > 900000.0) { MrBayesPrint ("%s %2d -- Trees with constraint \"%s\" are infinitely\n", spacer, j+1, tempName); MrBayesPrint ("%s more probable than those without \n", spacer); } else { MrBayesPrint ("%s %2d -- Trees with constraint \"%s\" are exp(%1.2lf)\n", spacer, j+1, tempName, relConstraintProbs[j]); MrBayesPrint ("%s times more probable than those without \n", spacer); } } else { if (relConstraintProbs[j] < -900000.0) { MrBayesPrint ("%s %2d -- Trees with constraint \"%s\" are infinitely\n", spacer, j+1, tempName); MrBayesPrint ("%s less probable than those without \n", spacer); } else { MrBayesPrint ("%s %2d -- Trees with constraint \"%s\" are exp(%1.2lf)\n", spacer, j+1, tempName, -relConstraintProbs[j]); MrBayesPrint ("%s times less probable than those without \n", spacer); } } */ } MrBayesPrint ("\n"); for (j=0; j 0) { MrBayesPrint ("----"); for (j=0; j%4d (%s) ", spacer, i+1, tempName); else MrBayesPrint ("%s %4d (%s) ", spacer, i+1, tempName); for (j=0; j<(maxLen-nameLen); j++) MrBayesPrint (" "); MrBayesPrint (" -- "); if (taxaInfo[i].isDeleted == YES) MrBayesPrint ("Deleted "); else MrBayesPrint ("Included"); MrBayesPrint (" "); for (j=0; jnodes[0]) { MrBayesPrint ("\n ERROR: Something wrong with user tree\n"); return (ERROR); } if (pPtr->anc == NULL) userTree->isRooted = YES; else { userTree->isRooted = NO; /* adjust number of nodes, since we originally thought the tree was rooted */ userTree->nIntNodes -= 1; userTree->nNodes -= 2; } if (userTree->isRooted == YES) { MrBayesPrint ("%s Defining a rooted user tree\n", spacer); pPtr = &userTree->nodes[nextAvailableNode]; nextAvailableNode++; pPtr->left = qPtr; qPtr->anc = pPtr; userTree->root = pPtr; } else { MrBayesPrint ("%s Defining an unrooted user tree\n", spacer); } i = numTaxa; if (userTree->isRooted == YES) FinishTree (userTree->root, &i, YES); else FinishTree (userTree->root, &i, NO); /* we are not going to worry here about the rooting of the user tree but we may want to move the calculation root if the tree is unrooted */ GetDownPass (userTree); isUserTreeDefined = YES; if (userTree->isRooted == NO) MoveCalculationRoot (userTree, outGroupNum); /* for debugging */ /* if (userTree->isRooted == YES) MrBayesPrint ("\n Tree is rooted:\n\n"); else MrBayesPrint ("\n Tree is unrooted:\n\n"); ShowNodes (userTree->root, 0, userTree->isRooted); getchar(); */ return (NO_ERROR); } int DoUserTreeParm (char *parmName, char *tkn) { int i, tempInt, howMany; MrBFlt tempD; char tempName[100]; if (defMatrix == NO) { MrBayesPrint ("%s A matrix must be specified before a user tree can be defined\n", spacer); return (ERROR); } if (expecting == Expecting(EQUALSIGN)) { /* delete old user tree if one is present */ if (isUserTreeDefined == YES) { FreeTree (userTree); } isUserTreeDefined = NO; memAllocs[ALLOC_USERTREE] = NO; if ((userTree = AllocateTree (numTaxa, YES)) == NULL) { MrBayesPrint ("%s Could not allocate space for user tree\n", spacer); return (ERROR); } else memAllocs[ALLOC_USERTREE] = YES; /* start recording user tree */ isFirstNode = YES; pPtr = qPtr = &userTree->nodes[0]; nextAvailableNode = 0; userBrlensDef = NO; foundColon = NO; for (i=0; inodes[nextAvailableNode]; nextAvailableNode++; isFirstNode = NO; userTree->root = pPtr; } else { if (nextAvailableNode+1 >= 2*numTaxa) { MrBayesPrint ("%s Too many nodes on user tree\n", spacer); return (ERROR); } if (pPtr->left == NULL) { pPtr = &userTree->nodes[nextAvailableNode]; nextAvailableNode++; qPtr->left = pPtr; pPtr->anc = qPtr; qPtr = pPtr; } else if (pPtr->right == NULL) { pPtr = &userTree->nodes[nextAvailableNode]; nextAvailableNode++; qPtr->right = pPtr; pPtr->anc = qPtr; qPtr = pPtr; } else if (pPtr->anc == NULL) { pPtr = &userTree->nodes[nextAvailableNode]; nextAvailableNode++; qPtr->anc = pPtr; pPtr->left = qPtr; qPtr = pPtr; userTree->root = pPtr; pPtr->marked = YES; } else { MrBayesPrint ("\n ERROR: Tree is not bifurcating\n"); return (ERROR); } } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(LEFTPAR); } else if (expecting == Expecting(ALPHA)) { if (nextAvailableNode+1 >= 2*numTaxa) { MrBayesPrint ("%s Too many nodes on user tree\n", spacer); return (ERROR); } /* Check to see if the name is in the list of taxon names. */ if (CheckString (tkn, taxaNames, &howMany) == ERROR) { MrBayesPrint ("%s Could not find taxon %s in list of taxa\n", spacer, tkn); return (ERROR); } if (tempSet[howMany-1] == YES) { MrBayesPrint ("%s Taxon name %s already used in tree\n", spacer, tkn); return (ERROR); } else tempSet[howMany-1] = YES; if (pPtr->left == NULL) { pPtr = &userTree->nodes[nextAvailableNode]; strcpy (pPtr->label, tkn); pPtr->index = howMany - 1; nextAvailableNode++; qPtr->left = pPtr; pPtr->anc = qPtr; qPtr = pPtr; } else if (pPtr->right == NULL) { pPtr = &userTree->nodes[nextAvailableNode]; strcpy (pPtr->label, tkn); pPtr->index = howMany - 1; nextAvailableNode++; qPtr->right = pPtr; pPtr->anc = qPtr; qPtr = pPtr; } else if (pPtr->anc == NULL) { pPtr = &userTree->nodes[nextAvailableNode]; strcpy (pPtr->label, tkn); pPtr->index = howMany - 1; nextAvailableNode++; qPtr->anc = pPtr; pPtr->left = qPtr; qPtr = pPtr; userTree->root = pPtr; pPtr->marked = YES; } else { MrBayesPrint ("%s Tree is not bifurcating\n", spacer); return (ERROR); } expecting = Expecting(COMMA); expecting |= Expecting(COLON); expecting |= Expecting(RIGHTPAR); } else if (expecting == Expecting(RIGHTPAR)) { if (pPtr->marked == NO) { if (pPtr->anc != NULL) { pPtr = pPtr->anc; qPtr = pPtr; } else { MrBayesPrint ("%s Cannot go down\n", spacer); return (ERROR); } } else { if (pPtr->left != NULL) { pPtr = pPtr->left; qPtr = pPtr; } else { MrBayesPrint ("%s Cannot go down\n", spacer); return (ERROR); } } expecting = Expecting(COMMA); expecting |= Expecting(COLON); expecting |= Expecting(RIGHTPAR); expecting |= Expecting(SEMICOLON); } else if (expecting == Expecting(COLON)) { foundColon = YES; expecting = Expecting(NUMBER); } else if (expecting == Expecting(COMMA)) { if (pPtr->marked == NO) { if (pPtr->anc != NULL) { pPtr = pPtr->anc; qPtr = pPtr; } else { MrBayesPrint ("%s Cannot go down\n", spacer); return (ERROR); } } else { if (pPtr->left != NULL) { pPtr = pPtr->left; qPtr = pPtr; } else { MrBayesPrint ("%s Cannot go down\n", spacer); return (ERROR); } } expecting = Expecting(ALPHA); expecting |= Expecting(NUMBER); expecting |= Expecting(LEFTPAR); } else if (expecting == Expecting(NUMBER)) { if (foundColon == YES) { /* branch length */ sscanf (token, "%lf", &tempD); if (pPtr->marked == NO) pPtr->length = tempD; else { if (pPtr->left != NULL) pPtr->left->length = tempD; else { MrBayesPrint ("%s Cannot assign branch length to left node\n", spacer); return (ERROR); } } userBrlensDef = YES; foundColon = NO; expecting = Expecting(COMMA); expecting |= Expecting(RIGHTPAR); } else { /* taxon number */ sscanf (token, "%d", &tempInt); if (nextAvailableNode+1 >= 2 * numTaxa) { MrBayesPrint ("%s Too many nodes on user tree\n", spacer); return (ERROR); } /* Check to see if the name is in the list of taxon names. */ if (CheckString (tkn, taxaNames, &howMany) == ERROR) { /* The number could not be found as a taxon name in the list of taxon names. We will assume that the user has then input taxa as numbers and not the names. */ if (tempSet[tempInt-1] == YES) { MrBayesPrint ("%s Taxon name %d has already been used in tree\n", spacer, tempInt); return (ERROR); } else tempSet[tempInt-1] = YES; tempInt--; } else { howMany--; /* The taxon name is in the list of taxon names */ if (howMany < 0 || howMany >= numTaxa) { MrBayesPrint ("%s Taxon number is out of range\n", spacer); return (ERROR); } if (tempSet[howMany] == YES) { MrBayesPrint ("%s Taxon %d has already been used in tree\n", spacer, howMany+1); return (ERROR); } else tempSet[howMany] = YES; tempInt = howMany; } if (GetNameFromString (taxaNames, tempName, tempInt+1) == ERROR) { MrBayesPrint ("%s Error getting taxon name\n", spacer); return (ERROR); } if (pPtr->left == NULL) { pPtr = &userTree->nodes[nextAvailableNode]; strcpy (pPtr->label, tempName); pPtr->index = tempInt; nextAvailableNode++; qPtr->left = pPtr; pPtr->anc = qPtr; qPtr = pPtr; } else if (pPtr->right == NULL) { pPtr = &userTree->nodes[nextAvailableNode]; strcpy (pPtr->label, tempName); pPtr->index = tempInt; nextAvailableNode++; qPtr->right = pPtr; pPtr->anc = qPtr; qPtr = pPtr; } else if (pPtr->anc == NULL) { pPtr = &userTree->nodes[nextAvailableNode]; strcpy (pPtr->label, tempName); pPtr->index = tempInt; nextAvailableNode++; qPtr->anc = pPtr; pPtr->left = qPtr; qPtr = pPtr; userTree->root = pPtr; pPtr->marked = YES; } else { MrBayesPrint ("%s Tree is not bifurcating\n", spacer); return (ERROR); } expecting = Expecting(COMMA); expecting |= Expecting(COLON); expecting |= Expecting(RIGHTPAR); } } return (NO_ERROR); MrBayesPrint ("%s", parmName); /* keep compiler happy */ } int DoVersion (void) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Version \n"); MrBayesPrint (" \n"); MrBayesPrint (" MrBayes v%s \n", VERSION_NUMBER); MrBayesPrint (" --------------------------------------------------------------------------- \n"); return (NO_ERROR); } unsigned long int Expecting (int y) { unsigned long int x; x = (unsigned long int)pow(2.0, (MrBFlt)y); return (x); } #ifdef USE_READLINE /* This function is for commandline substitution: first word is always a command */ char *command_generator(const char *text, int state) { static int list_index, len; char *command; if(state==0) { list_index=0; len=strlen(text); } while ((command=commands[list_index].string)!=NULL) { list_index++; if (strncasecmp(command,text,len)==0) /* memory is freed by the readline library so we need a strdup here */ return strdup(command); } return (char *)NULL; } #endif int FindValidCommand (char *tk, int *numMatches) { int i, j, tkLen, targetLen, numDiff; CmdType *p; p = commands + 0; tkLen = (int) strlen(tk); (*numMatches) = 0; for (i=0; istring); if (tkLen <= targetLen) { for (j=0, numDiff=0; jstring[j])) numDiff++; } if (numDiff == 0) { (*numMatches)++; commandPtr = p; if (tkLen == targetLen) break; } } p++; } inValidCommand = NO; if (*numMatches == 1) { inValidCommand = YES; return (NO_ERROR); } else return (ERROR); } int FindValidParam (char *tk, int *numMatches) { int i, j, tkLen, targetLen, numDiff; CmdType *p; ParmInfoPtr q; if (commandPtr) p = commandPtr; else { MrBayesPrint ("%s Command pointer is NULL\n", spacer); return (ERROR); } tkLen = (int) strlen(tk); *numMatches = 0; for (i=0; inumParms; i++) { q = paramTable + (p->parmList[i]); targetLen = (int) strlen(q->string); /*printf ("%s %d (%s %d)\n", q->string, targetLen, tk, p->numParms);*/ if (!strcmp(q->string, "Xxxxxxxxxx")) { (*numMatches)++; paramPtr = q; } if (tkLen <= targetLen) { for (j=0, numDiff=0; jstring[j])) numDiff++; } if (numDiff == 0) { (*numMatches)++; paramPtr = q; if (tkLen == targetLen) break; } } } if (*numMatches == 1) return (NO_ERROR); else return (ERROR); } void FinishTree (TreeNode *p, int *i, int isThisTreeRooted) { /* We only reindex the internal nodes of the tree. We assume that the tip nodes have already been indexed 0, 1, 2, ..., numTaxa-1. */ if (p != NULL) { FinishTree (p->left, i, isThisTreeRooted); FinishTree (p->right, i, isThisTreeRooted); p->marked = NO; if (p->left == NULL && p->right == NULL && p->anc != NULL) { } else if (p->left != NULL && p->right == NULL && p->anc == NULL) { if (isThisTreeRooted == YES) p->index = (*i)++; } else { p->index = (*i)++; } } } int FreeMatrix (void) { int memoryLetFree; memoryLetFree = NO; if (memAllocs[ALLOC_MATRIX] == YES) { free (matrix); memAllocs[ALLOC_MATRIX] = NO; memoryLetFree = YES; } if (memAllocs[ALLOC_CHARINFO] == YES) { free (charInfo); memAllocs[ALLOC_CHARINFO] = NO; memoryLetFree = YES; } if (memAllocs[ALLOC_TAXAINFO] == YES) { free (taxaInfo); memAllocs[ALLOC_TAXAINFO] = NO; memoryLetFree = YES; } if (memAllocs[ALLOC_PARTITIONNAMES] == YES) { free (partitionNames); memAllocs[ALLOC_PARTITIONNAMES] = NO; memoryLetFree = YES; } if (memAllocs[ALLOC_CHARSETNAMES] == YES) { free (charSetNames); memAllocs[ALLOC_CHARSETNAMES] = NO; memoryLetFree = YES; } if (memAllocs[ALLOC_TAXANAMES] == YES) { free (taxaNames); memAllocs[ALLOC_TAXANAMES] = NO; memoryLetFree = YES; } if (memAllocs[ALLOC_TMPSET] == YES) { free (tempSet); memAllocs[ALLOC_TMPSET] = NO; memoryLetFree = YES; } if (memAllocs[ALLOC_TAXASETNAMES] == YES) { free (taxaSetNames); memAllocs[ALLOC_TAXASETNAMES] = NO; memoryLetFree = YES; } if (memAllocs[ALLOC_CONSTRAINTNAMES] == YES) { free (constraintNames); memAllocs[ALLOC_CONSTRAINTNAMES] = NO; memoryLetFree = YES; } if (memAllocs[ALLOC_USERTREE] == YES) { FreeTree (userTree); memAllocs[ALLOC_USERTREE] = NO; memoryLetFree = YES; } if (memAllocs[ALLOC_TRANSFROM] == YES) { free (transFrom); memAllocs[ALLOC_TRANSFROM] = NO; memoryLetFree = YES; } if (memAllocs[ALLOC_TRANSTO] == YES) { free (transTo); memAllocs[ALLOC_TRANSTO] = NO; memoryLetFree = YES; } if (memoryLetFree == YES) MrBayesPrint ("%s Deleting matrix\n", spacer); /* reinitialize everything dependent on a matrix */ if (ReinitializeMrBayes() == ERROR) return (ERROR); return (NO_ERROR); } int GetNameFromString (char *s, char *tkn, int n) { int i, j, startI=0, numPrev; i = numPrev = 0; while (s[i] != '\0') { if (s[i] == '|') numPrev++; i++; } if (numPrev < n) { return (ERROR); } if (n == 1) startI = 0; else { i = j = 0; while (s[i] != '\0') { if (s[i] == '|') j++; i++; if (j == n - 1) { startI = i; break; } } } if (s[startI] == '\0') { MrBayesPrint ("%s String is too full\n", spacer); return (ERROR); } i = startI; j = 0; while(s[i] != '\0' && s[i] != '|') { tkn[j++] = s[i++]; if (s[i] == '\0') { MrBayesPrint ("%s String is too full\n", spacer); return (ERROR); } } tkn[j] = '\0'; return (NO_ERROR); } int GetNumPartDivisions (int n) { int i, divFound[MAX_NUM_DIVS], numDivs; for (i=0; i<")) { *temp++ = *tokenP++; *tokenType = WEIRD; } *temp = '\0'; } void GetUserDownPass (TreeNode *p, TreeNode **x, int *y) { if (p != NULL) { GetUserDownPass (p->left, x, y); GetUserDownPass (p->right, x, y); x[(*y)] = p; (*y)++; } } int GetUserHelp (char *helpTkn) { int i, j, tempInt; char yesNoStr[4]; if (!strcmp(helpTkn, "Begin")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Begin \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command is used to format data or commands in the program. The correct \n"); MrBayesPrint (" usage is \n"); MrBayesPrint (" \n"); MrBayesPrint (" begin ; \n"); MrBayesPrint (" \n"); MrBayesPrint (" The two valid uses of the \"begin\" command, then, are \n"); MrBayesPrint (" \n"); MrBayesPrint (" begin data; \n"); MrBayesPrint (" begin mrbayes; \n"); MrBayesPrint (" \n"); MrBayesPrint (" The \"data\" specifier is used to specify the beginning of a data block; your \n"); MrBayesPrint (" character data should follow. For example, the following is an example of \n"); MrBayesPrint (" a data block for four taxa and ten DNA sites: \n"); MrBayesPrint (" \n"); MrBayesPrint (" begin data; \n"); MrBayesPrint (" dimensions ntax=4 nchar=10; \n"); MrBayesPrint (" format datatype=dna; \n"); MrBayesPrint (" matrix \n"); MrBayesPrint (" taxon_1 AACGATTCGT \n"); MrBayesPrint (" taxon_2 AAGGATTCCA \n"); MrBayesPrint (" taxon_3 AACGACTCCT \n"); MrBayesPrint (" taxon_4 AAGGATTCCT \n"); MrBayesPrint (" ; \n"); MrBayesPrint (" end; \n"); MrBayesPrint (" \n"); MrBayesPrint (" The other commands -- dimensions, format, and matrix -- are discussed \n"); MrBayesPrint (" in the appropriate help menu. The only thing to note here is that the \n"); MrBayesPrint (" block begins with a \"begin data\" command. The \"mrbayes\" command is \n"); MrBayesPrint (" used to enter commands specific to the MrBayes program into the file. \n"); MrBayesPrint (" This allows you to automatically process commands on execution of the \n"); MrBayesPrint (" program. The following is a simple mrbayes block: \n"); MrBayesPrint (" \n"); MrBayesPrint (" begin mrbayes; \n"); MrBayesPrint (" charset first = 1-10\\3; \n"); MrBayesPrint (" charset second = 2-10\\3; \n"); MrBayesPrint (" charset third = 3-10\\3; \n"); MrBayesPrint (" end; \n"); MrBayesPrint (" \n"); MrBayesPrint (" This mrbayes block sets off the three \"charset\" commands, used to \n"); MrBayesPrint (" predefine some blocks of characters. The mrbayes block can be very useful. \n"); MrBayesPrint (" For example, in this case, it would save you the time of typing the char- \n"); MrBayesPrint (" acter sets each time you executed the file. Also, note that every \n"); MrBayesPrint (" \"begin \" command ends with an \"end\". Finally, you can \n"); MrBayesPrint (" have so-called foreign blocks in the file. An example of a foreign block \n"); MrBayesPrint (" would be \"begin paup\". The program will simply skip this block. This is \n"); MrBayesPrint (" useful because it means that you can use the same file for MrBayes, PAUP* \n"); MrBayesPrint (" or MacClade (although it isn't clear why you would want to use those other \n"); MrBayesPrint (" programs). \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "End")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" End \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command is used to terminate a data or mrbayes block. The correct \n"); MrBayesPrint (" usage is \n"); MrBayesPrint (" \n"); MrBayesPrint (" end; \n"); MrBayesPrint (" \n"); MrBayesPrint (" For more information on this, check the help for the \"begin\" command. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Endblock")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Endblock \n"); MrBayesPrint (" \n"); MrBayesPrint (" This is an older, deprecated version of \"End\", see that command. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Plot")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Plot \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command plots specified parameters in the .p file created by the \n"); MrBayesPrint (" program. The program prints two files during a MCMC analysis: a tree file \n"); MrBayesPrint (" and a parameter file. The parameter file has the extension \".p\". \n"); MrBayesPrint (" This command, plot, makes an x-y graph of the parameter over the course \n"); MrBayesPrint (" of the chain. The command can be useful for visually diagnosing convergence \n"); MrBayesPrint (" for many of the parameters of the phylogenetic model. The parameter to be \n"); MrBayesPrint (" plotted is specified by the \"parameter\" option. Several parameters can be \n"); MrBayesPrint (" plotted at once by using the \"match\" option, which has a default value of \n"); MrBayesPrint (" \"perfect\". For example, if you were to set \"parameter = pi\" and \n"); MrBayesPrint (" \"match = consistentwith\", then all of the state frequency parameters would \n"); MrBayesPrint (" be plotted. You can also set \"match=all\", in which case all of the \n"); MrBayesPrint (" parameters are plotted. \n"); MrBayesPrint (" \n"); MrBayesPrint (" Parameter Options Current Setting \n"); MrBayesPrint (" ------------------------------------------------------------ \n"); MrBayesPrint (" Filename %s \n", plotParams.plotFileName); MrBayesPrint (" Burnin %d \n", plotParams.plotBurnIn); MrBayesPrint (" Parameter %s \n", plotParams.parameter); MrBayesPrint (" Match Perfect/Consistentwith/All %s \n", plotParams.match); MrBayesPrint (" \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Dimensions")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Dimensions \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command is used in a data block to define the number of taxa and \n"); MrBayesPrint (" characters. The correct usage is \n"); MrBayesPrint (" \n"); MrBayesPrint (" dimensions ntax= nchar= \n"); MrBayesPrint (" \n"); MrBayesPrint (" The dimensions must be the first command in a data block. The following \n"); MrBayesPrint (" provides an example of the proper use of this command: \n"); MrBayesPrint (" \n"); MrBayesPrint (" begin data; \n"); MrBayesPrint (" dimensions ntax=4 nchar=10; \n"); MrBayesPrint (" format datatype=dna; \n"); MrBayesPrint (" matrix \n"); MrBayesPrint (" taxon_1 AACGATTCGT \n"); MrBayesPrint (" taxon_2 AAGGATTCCA \n"); MrBayesPrint (" taxon_3 AACGACTCCT \n"); MrBayesPrint (" taxon_4 AAGGATTCCT \n"); MrBayesPrint (" ; \n"); MrBayesPrint (" end; \n"); MrBayesPrint (" \n"); MrBayesPrint (" Here, the dimensions command tells MrBayes to expect a matrix with four \n"); MrBayesPrint (" taxa and 10 characters. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Format")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Format \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command is used in a data block to define the format of the char- \n"); MrBayesPrint (" acter matrix. The correct usage is \n"); MrBayesPrint (" \n"); MrBayesPrint (" format datatype= ... =

\n", chainParams.chainFileName); MrBayesPrint (" Startingtree Random/User %s \n", chainParams.chainStartTree); MrBayesPrint (" Nperts %d \n", chainParams.numStartPerts); PrintYesNo (chainParams.saveBrlens, yesNoStr); MrBayesPrint (" Savebrlens Yes/No %s \n", yesNoStr); PrintYesNo (chainParams.runWithData, yesNoStr); /* MrBayesPrint (" Data Yes/No %s \n", yesNoStr); */ MrBayesPrint (" Ordertaxa Yes/No %s \n", chainParams.orderTaxa == YES? "Yes" : "No"); MrBayesPrint (" \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Mcmcp")) { PrintYesNo (chainParams.saveBrlens, yesNoStr); MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Mcmcp \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command sets the parameters of the Markov chain Monte Carlo (MCMC) \n"); MrBayesPrint (" analysis without actually starting the chain. This command is identical \n"); MrBayesPrint (" in all respects to Mcmc, except that the analysis will not start after \n"); MrBayesPrint (" this command is issued. For more details on the options, check the help \n"); MrBayesPrint (" menu for Mcmc.\n"); MrBayesPrint (" \n"); MrBayesPrint (" Parameter Options Current Setting \n"); MrBayesPrint (" ----------------------------------------------------- \n"); MrBayesPrint (" Seed %ld \n", chainParams.chainSeed); MrBayesPrint (" Swapseed %ld \n", swapSeed); MrBayesPrint (" Ngen %d \n", chainParams.numGen); MrBayesPrint (" Nruns %d \n", chainParams.numRuns); MrBayesPrint (" Nchains %d \n", chainParams.numChains); MrBayesPrint (" Temp %lf \n", chainParams.chainTemp); MrBayesPrint (" Reweight , %1.2lf v %1.2lf ^ \n", chainParams.weightScheme[0], chainParams.weightScheme[1]); MrBayesPrint (" Swapfreq %d \n", chainParams.swapFreq); MrBayesPrint (" Nswaps %d \n", chainParams.numSwaps); MrBayesPrint (" Samplefreq %d \n", chainParams.sampleFreq); MrBayesPrint (" Printfreq %d \n", chainParams.printFreq); PrintYesNo (chainParams.printAll, yesNoStr); MrBayesPrint (" Printall Yes/No %s \n", yesNoStr); MrBayesPrint (" Printmax %d \n", chainParams.printMax); PrintYesNo (chainParams.mcmcDiagn, yesNoStr); MrBayesPrint (" Mcmcdiagn Yes/No %s \n", yesNoStr); MrBayesPrint (" Diagnfreq %d \n", chainParams.diagnFreq); MrBayesPrint (" Minpartfreq %1.2lf \n", chainParams.minPartFreq); PrintYesNo (chainParams.allChains, yesNoStr); MrBayesPrint (" Allchains Yes/No %s \n", yesNoStr); PrintYesNo (chainParams.allComps, yesNoStr); MrBayesPrint (" Allcomps Yes/No %s \n", yesNoStr); PrintYesNo (chainParams.relativeBurnin, yesNoStr); MrBayesPrint (" Relburnin Yes/No %s \n", yesNoStr); MrBayesPrint (" Burnin %d \n", chainParams.chainBurnIn); MrBayesPrint (" Burninfrac %1.2lf \n", chainParams.burninFraction); PrintYesNo (chainParams.stopRule, yesNoStr); MrBayesPrint (" Stoprule Yes/No %s \n", yesNoStr); MrBayesPrint (" Stopval %1.2lf \n", chainParams.stopVal); MrBayesPrint (" Filename %s.

\n", chainParams.chainFileName); MrBayesPrint (" Startingtree Random/User %s \n", chainParams.chainStartTree); MrBayesPrint (" Nperts %d \n", chainParams.numStartPerts); PrintYesNo (chainParams.saveBrlens, yesNoStr); MrBayesPrint (" Savebrlens Yes/No %s \n", yesNoStr); PrintYesNo (chainParams.runWithData, yesNoStr); /* MrBayesPrint (" Data Yes/No %s \n", yesNoStr); */ MrBayesPrint (" Ordertaxa Yes/No %s \n", chainParams.orderTaxa == YES? "Yes" : "No"); MrBayesPrint (" \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Set")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Set \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command is used to set some general features of the model or program \n"); MrBayesPrint (" behavior. The correct usage is \n"); MrBayesPrint (" \n"); MrBayesPrint (" set = ... = \n"); MrBayesPrint (" \n"); MrBayesPrint (" Only five parameters can be changed using \"set\". First, you can set \n"); MrBayesPrint (" the autoclose feature: \n"); MrBayesPrint (" \n"); MrBayesPrint (" set autoclose= \n"); MrBayesPrint (" \n"); MrBayesPrint (" If autoclose is set to yes, then the program will not prompt you during \n"); MrBayesPrint (" the course of executing a file. Second, you can set the partition that \n"); MrBayesPrint (" is in effect: \n"); MrBayesPrint (" \n"); MrBayesPrint (" set partition= \n"); MrBayesPrint (" \n"); MrBayesPrint (" A valid partition ID is either a number or a partition name. This command \n"); MrBayesPrint (" enforces use of a specific partitioning of the data. When the program \n"); MrBayesPrint (" executes, a default partition (that may not divide the data at all) is \n"); MrBayesPrint (" created called \"Default\". You can always go back to the original or \n"); MrBayesPrint (" default partition by typing \n"); MrBayesPrint (" \n"); MrBayesPrint (" set partition=default \n"); MrBayesPrint (" \n"); MrBayesPrint (" or \n"); MrBayesPrint (" \n"); MrBayesPrint (" set partition=1 \n"); MrBayesPrint (" \n"); MrBayesPrint (" Third, you can set the nowarnings feature: \n"); MrBayesPrint (" \n"); MrBayesPrint (" set nowarnings= \n"); MrBayesPrint (" \n"); MrBayesPrint (" If nowarnings is set to yes, then the program will not prompt you when \n"); MrBayesPrint (" overwriting or appending an output file that is already present. If \n"); MrBayesPrint (" nowarnings=no (the default setting) then the program prompts the user \n"); MrBayesPrint (" before overwriting output files. \n"); MrBayesPrint (" \n"); MrBayesPrint (" Fourth, you can set the quitonerror feature: \n"); MrBayesPrint (" \n"); MrBayesPrint (" set quitonerror= \n"); MrBayesPrint (" \n"); MrBayesPrint (" If quitonerror is set to yes, then the program will quit when an error is \n"); MrBayesPrint (" encountered, after printing an error message. If quitonerror=no (the default \n"); MrBayesPrint (" setting) then the program will wait for additional commands from the command \n"); MrBayesPrint (" line after printing the error message. \n"); MrBayesPrint (" \n"); MrBayesPrint (" Fifth, you can set the autooverwrite feature: \n"); MrBayesPrint (" \n"); MrBayesPrint (" set autooverwrite= \n"); MrBayesPrint (" \n"); MrBayesPrint (" When nowarnings is set to yes, by default MrBayes will overwrite output \n"); MrBayesPrint (" files. If autooverwrite=no, output will be appendend if the output file \n"); MrBayesPrint (" already exists. The default is autooverwrite=yes. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Charset")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Charset \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command defines a character set. The format for the charset command \n"); MrBayesPrint (" is \n"); MrBayesPrint (" \n"); MrBayesPrint (" charset = \n"); MrBayesPrint (" \n"); MrBayesPrint (" For example, \"charset first_pos = 1-720\\3\" defines a character set \n"); MrBayesPrint (" called \"first_pos\" that includes every third site from 1 to 720. \n"); MrBayesPrint (" The character set name cannot have any spaces in it. The slash (\\) \n"); MrBayesPrint (" is a nifty way of telling the program to assign every third (or \n"); MrBayesPrint (" second, or fifth, or whatever) character to the character set. \n"); MrBayesPrint (" This option is best used not from the command line, but rather as a \n"); MrBayesPrint (" line in the mrbayes block of a file. Note that you can use \".\" to \n"); MrBayesPrint (" stand in for the last character (e.g., charset 1-.\\3). \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Outgroup")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Outgroup \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command assigns a taxon to the outgroup. The correct usage is: \n"); MrBayesPrint (" \n"); MrBayesPrint (" outgroup / \n"); MrBayesPrint (" \n"); MrBayesPrint (" For example, \"outgroup 3\" assigns the third taxon in the matrix to be \n"); MrBayesPrint (" the outgroup. Similarly, \"outgroup Homo_sapiens\" assings the taxon \n"); MrBayesPrint (" \"Homo_sapiens\" to be the outgroup (assuming that there is a taxon named \n"); MrBayesPrint (" \"Homo_sapiens\" in the matrix). Only a single taxon can be assigned to \n"); MrBayesPrint (" be the outgroup. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Showtree")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Showtree \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command shows the current user tree. The correct usage \n"); MrBayesPrint (" is \"showtree\". \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Deroot")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Deroot \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command deroots the user tree. If the tree is already unrooted, a \n"); MrBayesPrint (" warning is issued. The correct usage is \"deroot\". \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Root")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Root \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command roots the tree. If the tree is already rooted, a warning \n"); MrBayesPrint (" is issued. The tree is rooted at the midpoint between the outgroup species \n"); MrBayesPrint (" and the ingroup species. The correct usage is \"root\". \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Taxset")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Taxset \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command defines a taxon set. The format for the taxset command \n"); MrBayesPrint (" is \n"); MrBayesPrint (" \n"); MrBayesPrint (" taxset = \n"); MrBayesPrint (" \n"); MrBayesPrint (" For example, \"taxset apes = Homo Pan Gorilla Orang gibbon\" defines a \n"); MrBayesPrint (" taxon set called \"apes\" that includes five taxa (namely, apes). \n"); MrBayesPrint (" You can assign up to 30 taxon sets. This option is best used \n"); MrBayesPrint (" not from the command line but rather as a line in the mrbayes block \n"); MrBayesPrint (" of a file. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Charstat")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Charstat \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command shows the status of all the characters. The correct usage \n"); MrBayesPrint (" is \n"); MrBayesPrint (" \n"); MrBayesPrint (" charstat \n"); MrBayesPrint (" \n"); MrBayesPrint (" After typing \"charstat\", the character number, whether it is excluded \n"); MrBayesPrint (" or included, and the partition identity are shown. The output is paused \n"); MrBayesPrint (" every 100 characters. This pause can be turned off by setting autoclose \n"); MrBayesPrint (" to \"yes\" (set autoclose=yes). \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Taxastat")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Taxastat \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command shows the status of all the taxa. The correct usage is \n"); MrBayesPrint (" \n"); MrBayesPrint (" taxastat \n"); MrBayesPrint (" \n"); MrBayesPrint (" After typing \"taxastat\", the taxon number, name, and whether it is \n"); MrBayesPrint (" excluded or included are shown. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Partition")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Partition \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command allows you to specify a character partition. The format for \n"); MrBayesPrint (" this command is \n"); MrBayesPrint (" \n"); MrBayesPrint (" partition = :, ..., \n"); MrBayesPrint (" \n"); MrBayesPrint (" For example, \"partition by_codon = 3:1st_pos,2nd_pos,3rd_pos\" specifies \n"); MrBayesPrint (" a partition called \"by_codon\" which consists of three parts (first, \n"); MrBayesPrint (" second, and third codon positions). Here, we are assuming that the sites \n"); MrBayesPrint (" in each partition were defined using the charset command. You can specify \n"); MrBayesPrint (" a partition without using charset as follows: \n"); MrBayesPrint (" \n"); MrBayesPrint (" partition by_codon = 3:1 4 6 9 12,2 5 7 10 13,3 6 8 11 14 \n"); MrBayesPrint (" \n"); MrBayesPrint (" However, we recommend that you use the charsets to define a set of char- \n"); MrBayesPrint (" acters and then use these predefined sets when defining the partition. \n"); MrBayesPrint (" Also, it makes more sense to define a partition as a line in the mrbayes \n"); MrBayesPrint (" block than to issue the command from the command line (then again, you \n"); MrBayesPrint (" may be a masochist, and want to do extra work). \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Exclude")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Exclude \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command excludes characters from the analysis. The correct usage is \n"); MrBayesPrint (" \n"); MrBayesPrint (" exclude \n"); MrBayesPrint (" \n"); MrBayesPrint (" or \n"); MrBayesPrint (" \n"); MrBayesPrint (" exclude - \n"); MrBayesPrint (" \n"); MrBayesPrint (" or \n"); MrBayesPrint (" \n"); MrBayesPrint (" exclude \n"); MrBayesPrint (" \n"); MrBayesPrint (" or some combination thereof. Moreover, you can use the specifier \"\\\" to \n"); MrBayesPrint (" exclude every nth character. For example, the following \n"); MrBayesPrint (" \n"); MrBayesPrint (" exclude 1-100\\3 \n"); MrBayesPrint (" \n"); MrBayesPrint (" would exclude every third character. As a specific example, \n"); MrBayesPrint (" \n"); MrBayesPrint (" exclude 2 3 10-14 22 \n"); MrBayesPrint (" \n"); MrBayesPrint (" excludes sites 2, 3, 10, 11, 12, 13, 14, and 22 from the analysis. Also, \n"); MrBayesPrint (" \n"); MrBayesPrint (" exclude all \n"); MrBayesPrint (" \n"); MrBayesPrint (" excludes all of the characters from the analysis. Excluding all characters \n"); MrBayesPrint (" does not leave you much information for inferring phylogeny. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Include")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Include \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command includes characters that were previously excluded from the \n"); MrBayesPrint (" analysis. The correct usage is \n"); MrBayesPrint (" \n"); MrBayesPrint (" include \n"); MrBayesPrint (" \n"); MrBayesPrint (" or \n"); MrBayesPrint (" \n"); MrBayesPrint (" include - \n"); MrBayesPrint (" \n"); MrBayesPrint (" or \n"); MrBayesPrint (" \n"); MrBayesPrint (" include \n"); MrBayesPrint (" \n"); MrBayesPrint (" or some combination thereof. Moreover, you can use the specifier \"\\\" to \n"); MrBayesPrint (" include every nth character. For example, the following \n"); MrBayesPrint (" \n"); MrBayesPrint (" include 1-100\\3 \n"); MrBayesPrint (" \n"); MrBayesPrint (" would include every third character. As a specific example, \n"); MrBayesPrint (" \n"); MrBayesPrint (" include 2 3 10-14 22 \n"); MrBayesPrint (" \n"); MrBayesPrint (" includes sites 2, 3, 10, 11, 12, 13, 14, and 22 from the analysis. Also, \n"); MrBayesPrint (" \n"); MrBayesPrint (" include all \n"); MrBayesPrint (" \n"); MrBayesPrint (" includes all of the characters in the analysis. Including all of the \n"); MrBayesPrint (" characters (even if many of them are bad) is a very total-evidence-like \n"); MrBayesPrint (" thing to do. Doing this will make a certain group of people very happy. \n"); MrBayesPrint (" On the other hand, simply using this program would make those same people \n"); MrBayesPrint (" unhappy. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Delete")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Delete \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command deletes taxa from the analysis. The correct usage is: \n"); MrBayesPrint (" \n"); MrBayesPrint (" delete ... \n"); MrBayesPrint (" \n"); MrBayesPrint (" A list of the taxon names or taxon numbers (labelled 1 to ntax in the order \n"); MrBayesPrint (" in the matrix) or taxset(s) can be used. For example, the following: \n"); MrBayesPrint (" \n"); MrBayesPrint (" delete 1 2 Homo_sapiens \n"); MrBayesPrint (" \n"); MrBayesPrint (" deletes taxa 1, 2, and the taxon labelled Homo_sapiens from the analysis. \n"); MrBayesPrint (" You can also use \"all\" to delete all of the taxa. For example, \n"); MrBayesPrint (" \n"); MrBayesPrint (" delete all \n"); MrBayesPrint (" \n"); MrBayesPrint (" deletes all of the taxa from the analysis. Of course, a phylogenetic anal- \n"); MrBayesPrint (" ysis that does not include any taxa is fairly uninteresting. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Restore")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Restore \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command restores taxa to the analysis. The correct usage is: \n"); MrBayesPrint (" \n"); MrBayesPrint (" restore ... \n"); MrBayesPrint (" \n"); MrBayesPrint (" A list of the taxon names or taxon numbers (labelled 1 to ntax in the order \n"); MrBayesPrint (" in the matrix) or taxset(s) can be used. For example, the following: \n"); MrBayesPrint (" \n"); MrBayesPrint (" restore 1 2 Homo_sapiens \n"); MrBayesPrint (" \n"); MrBayesPrint (" restores taxa 1, 2, and the taxon labelled Homo_sapiens to the analysis. \n"); MrBayesPrint (" You can also use \"all\" to restore all of the taxa. For example, \n"); MrBayesPrint (" \n"); MrBayesPrint (" restore all \n"); MrBayesPrint (" \n"); MrBayesPrint (" restores all of the taxa to the analysis. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Quit")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Quit \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command quits the program. The correct usage is: \n"); MrBayesPrint (" \n"); MrBayesPrint (" quit \n"); MrBayesPrint (" \n"); MrBayesPrint (" It is a very easy command to use properly. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Disclaimer")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Disclaimer \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command shows the disclaimer for the program. In short, the disclaimer \n"); MrBayesPrint (" states that the authors (John Huelsenbeck and Fredrik Ronquist) are not \n"); MrBayesPrint (" responsible for any silly things you may do to your computer or any \n"); MrBayesPrint (" unforseen but possibly nasty things the computer program may inadvertently \n"); MrBayesPrint (" do to you. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Unlink")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Unlink \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command unlinks model parameters across partitions of the data. The \n"); MrBayesPrint (" correct usage is: \n"); MrBayesPrint (" \n"); MrBayesPrint (" unlink = ( or ) \n"); MrBayesPrint (" \n"); MrBayesPrint (" A little background is necessary to understand this command. Upon exe- \n"); MrBayesPrint (" cution of a file, a default partition is set up. This partition refer- \n"); MrBayesPrint (" enced either by its name (\"default\") or number (0). If your data are \n"); MrBayesPrint (" all of one type, then this default partition does not actually divide up \n"); MrBayesPrint (" your characters. However, if your datatype is mixed, then the default \n"); MrBayesPrint (" partition contains as many divisions as there are datatypes in your \n"); MrBayesPrint (" character matrix. Of course, you can also define other partitions, and \n"); MrBayesPrint (" switch among them using the set command (\"set partition=\"). \n"); MrBayesPrint (" Importantly, you can also assign model parameters to individual part- \n"); MrBayesPrint (" itions or to groups of them using the \"applyto\" option in lset and \n"); MrBayesPrint (" prset. When the program attempts to perform an analysis, the model is \n"); MrBayesPrint (" set for individual partitions. If the same parameter applies to differ- \n"); MrBayesPrint (" partitions and if that parameter has the same prior, then the program \n"); MrBayesPrint (" will link the parameters: that is, it will use a single value for the \n"); MrBayesPrint (" parameter. The program's default, then, is to strive for parsimony. \n"); MrBayesPrint (" However, there are lots of cases where you may want unlink a parameter \n"); MrBayesPrint (" across partitions. For example, you may want a different transition/ \n"); MrBayesPrint (" transversion rate ratio to apply to different partitions. This command \n"); MrBayesPrint (" allows you to unlink the parameters, or to make them different across \n"); MrBayesPrint (" partitions. The converse of this command is \"link\", which links to- \n"); MrBayesPrint (" gether parameters that were previously told to be different. The list \n"); MrBayesPrint (" of parameters that can be unlinked includes: \n"); MrBayesPrint (" \n"); MrBayesPrint (" Tratio -- Transition/transversion rate ratio \n"); MrBayesPrint (" Revmat -- Substitution rates of GTR model \n"); MrBayesPrint (" Omega -- Nonsynonymous/synonymous rate ratio \n"); MrBayesPrint (" Statefreq -- Character state frequencies \n"); MrBayesPrint (" Shape -- Gamma shape parameter \n"); MrBayesPrint (" Pinvar -- Proportion of invariable sites \n"); MrBayesPrint (" Correlation -- Correlation parameter of autodiscrete gamma \n"); MrBayesPrint (" Switchrates -- Switching rates for covarion model \n"); MrBayesPrint (" Brlens -- Branch lengths of tree \n"); MrBayesPrint (" Topology -- Topology of tree \n"); MrBayesPrint (" Speciationrates -- Speciation rates for birth-death process \n"); MrBayesPrint (" Extinctionrates -- Extinction rates for birth-death process \n"); MrBayesPrint (" Theta -- Parameter for coalescence process \n"); MrBayesPrint (" Growthrate -- Growth rate of coalescence process \n"); MrBayesPrint (" \n"); MrBayesPrint (" For example, \n"); MrBayesPrint (" \n"); MrBayesPrint (" unlink shape=(all) \n"); MrBayesPrint (" \n"); MrBayesPrint (" unlinks the gamma shape parameter across all partitions of the data. \n"); MrBayesPrint (" You can use \"showmodel\" to see the current linking status of the \n"); MrBayesPrint (" characters. \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Link")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Link \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command links model parameters across partitions of the data. The \n"); MrBayesPrint (" correct usage is: \n"); MrBayesPrint (" \n"); MrBayesPrint (" link = ( or ) \n"); MrBayesPrint (" \n"); MrBayesPrint (" The list of parameters that can be linked includes: \n"); MrBayesPrint (" \n"); MrBayesPrint (" Tratio -- Transition/transversion rate ratio \n"); MrBayesPrint (" Revmat -- Substitution rates of GTR model \n"); MrBayesPrint (" Omega -- Nonsynonymous/synonymous rate ratio \n"); MrBayesPrint (" Statefreq -- Character state frequencies \n"); MrBayesPrint (" Shape -- Gamma shape parameter \n"); MrBayesPrint (" Pinvar -- Proportion of invariable sites \n"); MrBayesPrint (" Correlation -- Correlation parameter of autodiscrete gamma \n"); MrBayesPrint (" Switchrates -- Switching rates for covarion model \n"); MrBayesPrint (" Brlens -- Branch lengths of tree \n"); MrBayesPrint (" Topology -- Topology of tree \n"); MrBayesPrint (" Speciationrates -- Speciation rates for birth-death process \n"); MrBayesPrint (" Extinctionrates -- Extinction rates for birth-death process \n"); MrBayesPrint (" Theta -- Parameter for coalescence process \n"); MrBayesPrint (" Growthrate -- Growth rate of coalescence process \n"); MrBayesPrint (" \n"); MrBayesPrint (" For example, \n"); MrBayesPrint (" \n"); MrBayesPrint (" link shape=(all) \n"); MrBayesPrint (" \n"); MrBayesPrint (" links the gamma shape parameter across all partitions of the data. \n"); MrBayesPrint (" You can use \"showmodel\" to see the current linking status of the \n"); MrBayesPrint (" characters. For more information on this command, see the help menu \n"); MrBayesPrint (" for link's converse, unlink (\"help unlink\"); \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Help")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Help \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command provides useful information on the use of this program. The \n"); MrBayesPrint (" correct usage is \n"); MrBayesPrint (" \n"); MrBayesPrint (" help \n"); MrBayesPrint (" \n"); MrBayesPrint (" which gives a list of all available commands with a brief description of \n"); MrBayesPrint (" each or \n"); MrBayesPrint (" \n"); MrBayesPrint (" help \n"); MrBayesPrint (" \n"); MrBayesPrint (" which gives detailed information on the use of . \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Sump")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Sump \n"); MrBayesPrint (" \n"); MrBayesPrint (" During a MCMC analysis, MrBayes prints the sampled parameter values to a tab- \n"); MrBayesPrint (" delimited text file. This file has the extension \".p\". The command 'Sump' \n"); MrBayesPrint (" summarizes the information in the parameter file. By default, the name of the \n"); MrBayesPrint (" parameter file is assumed to be the name of the last matrix-containing nexus \n"); MrBayesPrint (" file, but with a '.p' extension. You can set 'Sump' to summarize the infor- \n"); MrBayesPrint (" mation in any other parameter file by setting the 'filename' option to the \n"); MrBayesPrint (" appropriate file name. The 'Sump' command does not require a matrix to be \n"); MrBayesPrint (" read in first. When you invoke the 'Sump' command, three items are output: \n"); MrBayesPrint (" (1) a generation plot of the likelihood values; (2) estimates of the mar- \n"); MrBayesPrint (" ginal likelihood of the model; and (3) a table with the mean, variance, and \n"); MrBayesPrint (" 95 percent credible interval for the sampled parameters. Each of these items \n"); MrBayesPrint (" can be switched on or off using the options 'Plot', 'Marglike', and 'Table'. \n"); MrBayesPrint (" By default, all three items are output but only to the screen. If output to \n"); MrBayesPrint (" a file is also desired, set 'Printtofile' to 'Yes'. The name of the output \n"); MrBayesPrint (" file is specified by setting the 'Outputname' option. When a new matrix is \n"); MrBayesPrint (" read in or when the 'Mcmc' output filename or 'Sump' input filename is \n"); MrBayesPrint (" changed, the 'Sump' outputname is changed as well. If you want to output to \n"); MrBayesPrint (" another file than the default, make sure you specify the outputname every \n"); MrBayesPrint (" time you invoke 'Sump'. If the specified outputfile already exists, you will \n"); MrBayesPrint (" be prompted about whether you like to overwrite it or append to it. This \n"); MrBayesPrint (" behavior can be altered using 'Set nowarn=yes'; see the help for the 'Set' \n"); MrBayesPrint (" command. When running 'Sump' you typically want to discard a specified \n"); MrBayesPrint (" number of samples from the beginning of the chain as the burn in. Note that \n"); MrBayesPrint (" the 'Burnin' value of the 'Sump' command is set separately from the 'Burnin' \n"); MrBayesPrint (" values of the 'Sumt' and 'Mcmc' commands. That is, if you issue \n"); MrBayesPrint (" \n"); MrBayesPrint (" sump burnin = 4000 \n"); MrBayesPrint (" sumt burnin = 2000 \n"); MrBayesPrint (" sump \n"); MrBayesPrint (" \n"); MrBayesPrint (" the burnin of the last 'Sump' command is 4000 and not 2000. The burnin \n"); MrBayesPrint (" values are reset to 0 every time a new matrix is read in. Similarly, 'Plot', \n"); MrBayesPrint (" 'Marglike' and 'Table' are all set to 'Yes' and 'Printtofile' to 'No' (the \n"); MrBayesPrint (" default values) when a new matrix is processed. If you have run several \n"); MrBayesPrint (" independent MCMC analyses, you may want to summarize and compare the samples \n"); MrBayesPrint (" from each of these runs. To do this, set 'Nruns' to the number of runs you \n"); MrBayesPrint (" want to compare and make sure that the '.p' files are named using the MrBayes \n"); MrBayesPrint (" convention (.run1.p, .run2.p, etc). When you run several \n"); MrBayesPrint (" independent analyses simultaneously in MrBayes, the 'Nruns' and 'Filename' \n"); MrBayesPrint (" options are automatically set such that 'Sump' will summarize all the resul- \n"); MrBayesPrint (" ting output files. \n"); MrBayesPrint (" \n"); MrBayesPrint (" Options: \n"); MrBayesPrint (" \n"); MrBayesPrint (" Burnin -- Determines the number of samples that will be discarded from \n"); MrBayesPrint (" the input file before calculating summary statistics. If there\n"); MrBayesPrint (" are several input files, the same number of samples will be \n"); MrBayesPrint (" discarded from each. Note that the burnin is set separately \n"); MrBayesPrint (" for the 'sump', 'sumt', and 'mcmc' commands. \n"); MrBayesPrint (" Nruns -- Determines how many '.p' files from independent analyses that \n"); MrBayesPrint (" will be summarized. If Nruns > 1 then the names of the files \n"); MrBayesPrint (" are derived from 'Filename' by adding '.run1.p', '.run2.p', \n"); MrBayesPrint (" etc. If Nruns=1, then the single file name is obtained by \n"); MrBayesPrint (" adding '.p' to 'Filename'. \n"); MrBayesPrint (" Filename -- The name of the file to be summarized. This is the base of the\n"); MrBayesPrint (" file name to which endings are added according to the current \n"); MrBayesPrint (" setting of the 'Nruns' parameter. If 'Nruns' is 1, then only \n"); MrBayesPrint (" '.p' is added to the file name. Otherwise, the endings will \n"); MrBayesPrint (" be '.run1.p', '.run2.p', etc. \n"); MrBayesPrint (" Printtofile -- Determines whether results will be printed to file. \n"); MrBayesPrint (" Outputname -- Name of the file to which 'sump' results will be printed if \n"); MrBayesPrint (" 'Printtofile' is set to YES. \n"); MrBayesPrint (" Plot -- Determines whether a likelihood plot should be output. \n"); MrBayesPrint (" Marglike -- Determines whether estimates of marginal model likelihoods \n"); MrBayesPrint (" should be calculated. The marginal model likelihoods are use- \n"); MrBayesPrint (" ful in Bayesian model testing. \n"); MrBayesPrint (" Table -- Determines whether the table summarizing the parameter value \n"); MrBayesPrint (" samples should be output. \n"); MrBayesPrint (" \n"); MrBayesPrint (" Current settings: \n"); MrBayesPrint (" \n"); MrBayesPrint (" Parameter Options Current Setting \n"); MrBayesPrint (" -------------------------------------------------------- \n"); MrBayesPrint (" Burnin %d \n", sumpParams.sumpBurnIn); MrBayesPrint (" Nruns %d \n", sumpParams.numRuns); if (sumpParams.numRuns == 1) MrBayesPrint (" Filename %s<.p>\n", sumpParams.sumpFileName); else MrBayesPrint (" Filename %s<.run.p>\n", sumpParams.sumpFileName); MrBayesPrint (" Printtofile Yes/No %s \n", sumpParams.printToFile == YES ? "Yes" : "No"); MrBayesPrint (" Outputname %s\n", sumpParams.sumpOutfile); MrBayesPrint (" Plot Yes/No %s \n", sumpParams.plot == YES ? "Yes" : "No"); MrBayesPrint (" Marglike Yes/No %s \n", sumpParams.margLike == YES ? "Yes" : "No"); MrBayesPrint (" Table Yes/No %s \n", sumpParams.table == YES ? "Yes" : "No"); MrBayesPrint (" \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Comparetree")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Comparetree \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command compares the trees in two files, called \"filename1\" and \n"); MrBayesPrint (" \"filename2\". It will output a bivariate plot of the split frequencies \n"); MrBayesPrint (" as well as plots of the tree distance as a function of the generation. The \n"); MrBayesPrint (" plots can be used to get a quick indication of whether two runs have con- \n"); MrBayesPrint (" verged onto the same set of trees. The \"Comparetree\" command will also \n"); MrBayesPrint (" produce a \".parts\" file and a \".dists\" file (these file endings are added \n"); MrBayesPrint (" to the end of the \"Outputname\"). The \".parts\" file contains the paired \n"); MrBayesPrint (" split frequencies from the two tree samples; the \".dists\" file contains the \n"); MrBayesPrint (" tree distance values. Note that the \"Sumt\" command provides a different \n"); MrBayesPrint (" set of convergence diagnostics tools that you may also want to explore. Un- \n"); MrBayesPrint (" like \"Comparetree\", \"Sumt\" can compare more than two tree samples and \n"); MrBayesPrint (" will calculate consensus trees and split frequencies from the pooled samples. \n"); MrBayesPrint (" \n"); MrBayesPrint (" Parameter Options Current Setting \n"); MrBayesPrint (" -------------------------------------------------------- \n"); MrBayesPrint (" Filename1 %s \n", comptreeParams.comptFileName1); MrBayesPrint (" Filename2 %s \n", comptreeParams.comptFileName2); MrBayesPrint (" Outputname %s \n", comptreeParams.comptOutfile); MrBayesPrint (" Burnin %d \n", comptreeParams.comptBurnIn); MrBayesPrint (" \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Sumt")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Sumt \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command is used to produce summary statistics for trees sampled during \n"); MrBayesPrint (" a Bayesian MCMC analysis. You can either summarize trees from one individual \n"); MrBayesPrint (" analysis, or trees coming from several independent analyses. In either case, \n"); MrBayesPrint (" all the sampled trees are read in and the proportion of the time any single \n"); MrBayesPrint (" taxon bipartition is found is counted. The proportion of the time that the \n"); MrBayesPrint (" bipartition is found is an approximation of the posterior probability of the \n"); MrBayesPrint (" bipartition. (Remember that a taxon bipartition is defined by removing a \n"); MrBayesPrint (" branch on the tree, dividing the tree into those taxa to the left and right \n"); MrBayesPrint (" of the removed branch. This set is called a taxon bipartition.) The branch \n"); MrBayesPrint (" length of the bipartition is also recorded, if branch lengths have been saved \n"); MrBayesPrint (" to file. The result is a list of the taxon bipartitions found, the frequency \n"); MrBayesPrint (" with which they were found, the posterior probability of the bipartition \n"); MrBayesPrint (" and, if the branch lengths were recorded, the mean and variance of the length \n"); MrBayesPrint (" of the branch. \n"); MrBayesPrint (" \n"); MrBayesPrint (" The partition information is output to a file with the suffix \".parts\". \n"); MrBayesPrint (" A consensus tree is also printed to a file with the suffix \".con\" and \n"); MrBayesPrint (" printed to the screen as a cladogram, and as a phylogram if branch lengths \n"); MrBayesPrint (" have been saved. The consensus tree is either a 50 percent majority rule tree \n"); MrBayesPrint (" or a majority rule tree showing all compatible partitions. If branch lengths \n"); MrBayesPrint (" have been recorded during the run, the \".con\" file will contain a consensus \n"); MrBayesPrint (" tree with branch lengths and interior nodes labelled with support values. \n"); MrBayesPrint (" This tree can be viewed in a program such as TreeView. \n"); MrBayesPrint (" \n"); MrBayesPrint (" Finally, MrBayes produces a file with the ending \".trprobs\" that contains a \n"); MrBayesPrint (" list of all the trees that were found during the MCMC analysis, sorted by \n"); MrBayesPrint (" their probabilities. This list of trees can be used to construct a credible \n"); MrBayesPrint (" set of trees. For example, if you want to construct a 95 percent credible set \n"); MrBayesPrint (" of trees, you include all of those trees whose cumulated probability is less \n"); MrBayesPrint (" than or equal to 0.95. You have the option of displaying the trees to the \n"); MrBayesPrint (" screen using the \"Showtreeprobs\" option. The default is to not display the \n"); MrBayesPrint (" trees to the screen; the number of different trees sampled by the chain can \n"); MrBayesPrint (" be quite large. If you are analyzing a large set of taxa, you may actually \n"); MrBayesPrint (" want to skip the calculation of tree probabilities entirely by setting \n"); MrBayesPrint (" \"Calctreeprobs\" to NO. \n"); MrBayesPrint (" \n"); MrBayesPrint (" When calculating summary statistics you probably want to skip those trees that\n"); MrBayesPrint (" were sampled in the initial part of the run, the so-called burn-in period. The\n"); MrBayesPrint (" number of skipped samples is controlled by the \"burnin\" setting. The default\n"); MrBayesPrint (" is 0 but you typically want to override this setting. \n"); MrBayesPrint (" \n"); MrBayesPrint (" If you are summarizing the trees sampled in several independent analyses, \n"); MrBayesPrint (" such as those resulting from setting the \"Nruns\" option of the \"Mcmc\" com-\n"); MrBayesPrint (" mand to a value larger than 1, MrBayes will also calculate convergence diag- \n"); MrBayesPrint (" nostics for the sampled topologies and branch lengths. These values can help \n"); MrBayesPrint (" you determine whether it is likely that your chains have converged. \n"); MrBayesPrint (" \n"); MrBayesPrint (" The \"Sumt\" command expands the \"Filename\" according to the current values \n"); MrBayesPrint (" of the \"Nruns\" and \"Ntrees\" options. For instance, if both \"Nruns\" and \n"); MrBayesPrint (" \"Ntrees\" are set to 1, \"Sumt\" will try to open a file named \n"); MrBayesPrint (" \".t\". If \"Nruns\" is set to 2 and \"Ntrees\" to 1, then \"Sumt\" \n"); MrBayesPrint (" will open two files, \".run1.t\" and \".run2.t\", etc. \n"); MrBayesPrint (" By default, the \"Filename\" option will be set such that \"Sumt\" auto- \n"); MrBayesPrint (" matically summarizes all the results from your immediately preceding \"Mcmc\" \n"); MrBayesPrint (" command. You can also use the \"Sumt\" command to summarize tree samples in \n"); MrBayesPrint (" older analyses. If you want to do that, remember to first read in a matrix \n"); MrBayesPrint (" so that MrBayes knows what taxon names to expect in the trees. Then set the \n"); MrBayesPrint (" \"Nruns\", \"Ntrees\" and \"Filename\" options appropriately. \n"); MrBayesPrint (" \n"); MrBayesPrint (" Options: \n"); MrBayesPrint (" \n"); MrBayesPrint (" Burnin -- Determines the number of samples that will be discarded from \n"); MrBayesPrint (" the input file before calculating summary statistics. If \n"); MrBayesPrint (" there are several input files, the same number of samples \n"); MrBayesPrint (" will be discarded from each. Note that the burnin is set \n"); MrBayesPrint (" separately for the 'sumt', 'sump', and 'mcmc' commands. \n"); MrBayesPrint (" Nruns -- Determines how many '.t' files from independent analyses that\n"); MrBayesPrint (" will be summarized. If Nruns > 1 then the names of the files \n"); MrBayesPrint (" are derived from 'Filename' by adding '.run1.t', '.run2.t', \n"); MrBayesPrint (" etc. If Nruns=1 and Ntrees=1 (see below), then only '.t' is \n"); MrBayesPrint (" added to 'Filename'. \n"); MrBayesPrint (" Ntrees -- Determines how many trees there are in the sampled model. If \n"); MrBayesPrint (" 'Ntrees' > 1 then the names of the files are derived from \n"); MrBayesPrint (" 'Filename' by adding '.tree1.t', '.tree2.t', etc. If there \n"); MrBayesPrint (" are both multiple trees and multiple runs, the filenames will\n"); MrBayesPrint (" be '.tree1.run1.t', '.tree1.run2.t', etc.\n"); MrBayesPrint (" Filename -- The name of the file(s) to be summarized. This is the base of\n"); MrBayesPrint (" the file name, to which endings are added according to the \n"); MrBayesPrint (" current settings of the 'Nruns' and 'Ntrees' options. \n"); MrBayesPrint (" Displaygeq -- The minimum probability of partitions to display. \n"); MrBayesPrint (" Contype -- Type of consensus tree. 'Halfcompat' results in a 50 % major-\n"); MrBayesPrint (" ity rule tree, 'Allcompat' adds all compatible groups to such\n"); MrBayesPrint (" a tree. \n"); MrBayesPrint (" Calctreeprobs -- Determines whether tree probabilities should be calculated. \n"); MrBayesPrint (" Showtreeprobs -- Determines whether tree probabilities should be displayed on \n"); MrBayesPrint (" screen. \n"); MrBayesPrint (" \n"); MrBayesPrint (" Current settings: \n"); MrBayesPrint (" \n"); MrBayesPrint (" Parameter Options Current Setting \n"); MrBayesPrint (" -------------------------------------------------------- \n"); MrBayesPrint (" Burnin %d \n", sumtParams.sumtBurnIn); MrBayesPrint (" Nruns %d \n", sumtParams.numRuns); MrBayesPrint (" Ntrees %d \n", sumtParams.numTrees); if (sumtParams.numRuns == 1 && sumtParams.numTrees == 1) MrBayesPrint (" Filename %s<.t>\n", sumtParams.sumtFileName); else if (sumtParams.numRuns == 1 && sumtParams.numTrees > 1) MrBayesPrint (" Filename %s<.tree.t>\n", sumtParams.sumtFileName); else if (sumtParams.numRuns > 1 && sumtParams.numTrees == 1) MrBayesPrint (" Filename %s<.run.t>\n", sumtParams.sumtFileName); else if (sumtParams.numRuns > 1 && sumtParams.numTrees > 1) MrBayesPrint (" Filename %s<.tree.run.t>\n", sumtParams.sumtFileName); MrBayesPrint (" Displaygeq %1.2lf \n", sumtParams.freqDisplay); MrBayesPrint (" Contype Halfcompat/Allcompat %s\n", sumtParams.sumtConType); MrBayesPrint (" Calctreeprobs Yes/No %s \n", sumtParams.calcTrprobs == YES ? "Yes" : "No"); MrBayesPrint (" Showtreeprobs Yes/No %s \n", sumtParams.showSumtTrees == YES ? "Yes" : "No"); MrBayesPrint (" \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Tree")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Tree \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command is used by MrBayes to write trees to a nexus tree file. Trees \n"); MrBayesPrint (" are written in the Newick format. For instance, \n"); MrBayesPrint (" \n"); MrBayesPrint (" tree ((1,2),3,4); \n"); MrBayesPrint (" \n"); MrBayesPrint (" describes an unrooted tree with taxa 1 and 2 being more closely related to \n"); MrBayesPrint (" each other than to taxa 3 and 4. If branch lengths are saved to file, they \n"); MrBayesPrint (" are given after a colon sign immediately following the terminal taxon or the \n"); MrBayesPrint (" interior node they refer to. An example of an unrooted tree with branch \n"); MrBayesPrint (" lengths is: \n"); MrBayesPrint (" \n"); MrBayesPrint (" tree ((1:0.064573,2:0.029042):0.041239,3:0.203988,4:0.187654); \n"); MrBayesPrint (" \n"); MrBayesPrint (" Trees that are rooted (clock trees) are written with a basal dichotomy \n"); MrBayesPrint (" instead of a basal trichotomy. If the tree described above had been rooted \n"); MrBayesPrint (" on the branch leading to taxon 4, it would have been represented as: \n"); MrBayesPrint (" \n"); MrBayesPrint (" tree (((1,2),3),4); \n"); MrBayesPrint (" \n"); MrBayesPrint (" --------------------------------------------------------------------------- \n"); } else if (!strcmp(helpTkn, "Lset")) { MrBayesPrint (" --------------------------------------------------------------------------- \n"); MrBayesPrint (" Lset \n"); MrBayesPrint (" \n"); MrBayesPrint (" This command sets the parameters of the likelihood model. The likelihood \n"); MrBayesPrint (" function is the probability of observing the data conditional on the phylo- \n"); MrBayesPrint (" genetic model. In order to calculate the likelihood, you must assume a \n"); MrBayesPrint (" model of character change. This command lets you tailor the biological \n"); MrBayesPrint (" assumptions made in the phylogenetic model. The correct usage is \n"); MrBayesPrint (" \n"); MrBayesPrint (" lset =