function compareTwoModels (mdl1, mdl2, rt1, rt2, fr1, fr2, useChiBar) { idx1 = mdl1*8+2*rt1+fr1; idx2 = mdl2*8+2*rt2+fr2; if (cacheMatrix[idx1][0]==0) { res1 = runAModel (modelStrings[mdl1],rt1,fr1,1,idx1); cacheMatrix[idx1][0] = res1[1][0]; cacheMatrix[idx1][1] = res1[1][1]+3*fr1; } if (cacheMatrix[idx2][0]==0) { res2 = runAModel (modelStrings[mdl2],rt2,fr2,1,idx2); cacheMatrix[idx2][0] = res2[1][0]; cacheMatrix[idx2][1] = res2[1][1]+3*fr2; } LRT = 2*(cacheMatrix[idx2][0]-cacheMatrix[idx1][0]); DEGF = cacheMatrix[idx2][1]-cacheMatrix[idx1][1]; if (LRT<=0) { return 1; } if (useChiBar) { return .5-.5*CChi2(LRT,DEGF); } return 1-CChi2(LRT,DEGF); } /**************************************************************************/ function echoModelSpec (modelString, modelRate, modelFreq) { fprintf (stdout, "\n\nTo define this model (if it isn't predefined) for analyses,\nUse 'Custom' model with the following options:\n", "Model String:", modelString, "\n"); fprintf (stdout, "Model Options: "); if (modelRate==0) { fprintf (stdout, "Global"); } else { if (modelRate==1) { fprintf (stdout, "Rate Variation, then choose the Gamma distribution"); } else { if (modelRate==2) { fprintf (stdout, "Rate Variation, then choose the Gamma+Inv distribution"); } else { if (modelRate==3) { fprintf (stdout, "Rate Variation, then choose the Inv Class distribution"); } } } } fprintf (stdout, "\nEquilibrium Frequencies Option: "); if (modelFreq) { fprintf (stdout, "Observed\n\n"); } else { fprintf (stdout, "Equal\n\n"); } return 1; } /**************************************************************************/ function reportTest (idx1, idx2, idx3, idx4, idx5, idx6, pValue, rt1, rt2) { modelName1 = modelNameStrings[idx1][idx5]; modelName2 = modelNameStrings[idx2][idx6]; if (rt1==1) { modelName1 = modelName1+"+G"; } if (rt1==2) { modelName1 = modelName1+"+G+I"; } if (rt1==3) { modelName1 = modelName1+"+I"; } if (rt2==1) { modelName2 = modelName2+"+G"; } if (rt2==2) { modelName2 = modelName2+"+G+I"; } if (rt2==3) { modelName2 = modelName2+"+I"; } fprintf (stdout, "\n\tNull:", modelName1, "\n\t\tLog-likelihood = ", Format(cacheMatrix[idx3][0],12,4), ", ", cacheMatrix[idx3][1], " parameters."); fprintf (stdout, "\n\tAlt :", modelName2, "\n\t\tLog-likelihood = ", Format(cacheMatrix[idx4][0],12,4), ", ", cacheMatrix[idx4][1], " parameters."); fprintf (stdout, "\n\n\tLR statistic : ", 2*(cacheMatrix[idx4][0]-cacheMatrix[idx3][0]), "\n\tDegrees of freedom : ",cacheMatrix[idx4][1]-cacheMatrix[idx3][1], "\n\tP-Value : ", pValue); if (pValueG and C<->T (transition) rates.\n"); } pVal = compareTwoModels (1,2,0,0,chosenFreqs,chosenFreqs,0); chosen3 = (pVal0); /* define the rate matrix */ r = setElement (0,1,modelSpecString[0]); r = setElement (0,2,modelSpecString[1]); r = setElement (0,3,modelSpecString[2]); r = setElement (1,2,modelSpecString[3]); r = setElement (1,3,modelSpecString[4]); r = setElement (2,3,modelSpecString[5]); /* define rate variation */ if (gammaType==1) { global alpha = .5; alpha:>0.01;alpha:<100; category c = (classCount, EQUAL, MEAN, GammaDist(_x_,alpha,alpha), CGammaDist(_x_,alpha,alpha), 0 , 1e25, CGammaDist(_x_,alpha+1,alpha) ); } else { if (gammaType==2) { global alpha = .5; alpha:>0.01;alpha:<100; global P; P :< 1-(1e-10); P = 1/(classCount+1); catFreqMatrix = {classCount+1,1}; catFreqMatrix [0] := P; for (h=1; h<=classCount;h=h+1) { catFreqMatrix [h] := (1-P)/classCount__; } category c = (classCount+1, catFreqMatrix, MEAN, (1-P)*GammaDist(_x_,alpha,alpha)*(_x_>0), (1-P)*CGammaDist(_x_,alpha,alpha)*(_x_>0)+P, 0, 1e25, (1-P)*CGammaDist(_x_,alpha+1,alpha)*(_x_>0) ); } else { if (gammaType==3) { global P; P :< 1-(1e-10); P = 1/2; catFreqMatrix = {2,1}; catFreqMatrix [0] := P; catFreqMatrix [1] := (1-P); catRateMatrix = {{0,1}}; category c = (2, catFreqMatrix, MEAN, , catRateMatrix, 0, 1e25, ); } } } if (freqType) { Model testingModel = (m,PI_EFV); } else { Model testingModel = (m,quarters_EFV); } if (doRun) { Tree MTTree = treeString; LikelihoodFunction lf = (filteredData, MTTree); Optimize (res,lf); if (Rows (savedMLEs)==1) { savedMLEs = {100,Columns (res)+10}; savedParNames = {100,Columns (res)+10}; for (kk=0; kk<100; kk=kk+1) { for (jj=0; jj=1)) { fprintf (stdout, "\nModel rejection level (e.g. 0.05):"); fscanf (stdin,"Number", rejectAt); } } if (runType) { aicMdl = doAICTest (1); fprintf (stdout, "\n\nAIC based model: ",aicMdl,", AIC = ", aicScore); } if (runType!=1) { hMdl = doHierarchicalTest (1); } OPTIMIZE_SUMMATION_ORDER = 0; if (runType!=1) { res = runAModel (modelStrings[chosenMatrix],chosenRates,chosenFreqs,0,0); Tree MTTree = treeString; LikelihoodFunction AIC_LF = (filteredData, MTTree); idx1 = 8*chosenMatrix+2*chosenRates+chosenFreqs; for (k=0; k