int CConfigure::GetIntParam(const string& astrKey,const string& astrSection,const string& astrCfgFile){ string lstrValue = GetStrParam(astrKey,astrSection,astrCfgFile); return atoi(lstrValue.c_str()); }
char* CJPersistFile::Get256CharStrParam( U32 parentId, U32 parentIndex, U32 childId, U32 childIndex) { return GetStrParam(parentId, parentIndex=0, childId=eNONE, childIndex);}
void ReadParams(int argc, char **argv) { int i, j, k; char ch, *P, st[4]; int modelTwoArgs = 0; model=NONE; scaleTrees=0; treeScale=0.0; scaleBranches=0; branchScale=0.0; maxPartitions=1; numPartitions=1; userSeed = 0; numCats=1; rateHetero=NoRates; catRate[0]=1.0; gammaShape=1.0; invariableSites=0; proportionInvariable = 0.0; equalFreqs = 1; equalTstv = 1; tstv=0.50002; for (i = 0; i < NUM_AA_REL_RATES; i++) { aaRelativeRate[i] = 1.0; } for (i = 0; i < NUM_AA; i++) { aaFreq[i] = 1.0; } aaFreqSet = 0; numSites=-1; numDatasets=1; ancestorSeq=0; writeAncestors=0; writeRates=0; verbose=1; fileFormat = PHYLIPFormat; quiet=0; treeFile=0; textFile=0; for (i=1; i<argc; i++) { P=argv[i]; if (*P=='-') { P++; ch=toupper(*P); P++; switch (ch) { case 'H': PrintTitle(); PrintUsage(); exit(0); break; case 'M': k = i; if (GetStrParam(argc, argv, &i, P, st, 3)) { fprintf(stderr, "Bad (or missing) Model Code: %s\n\n", argv[i]); exit(1); } P=st; if (i > k) { modelTwoArgs = 1; } model=-1; for (j=F84; j<numModels; j++) { if (strncmp(P, modelNames[j], 3)==0) { model=j; if (model <= GTR) { isNucModel = 1; numStates = 4; } else { isNucModel = 0; numStates = 20; } } else if (strncmp(P, "REV", 3)==0) { model=GTR; isNucModel = 1; numStates = 4; } } if (model==-1) { fprintf(stderr, "Unknown Model: %s\n\n", argv[i]); exit(1); } break; } } } if (model==NONE) { fprintf(stderr, "No model has been specified (use the -m option)\n\n"); PrintUsage(); exit(1); } for (i=1; i<argc; i++) { P=argv[i]; if (*P!='-') { if (treeFile) { fprintf(stderr, "Illegal command parameter: %s\n\n", argv[i]); PrintUsage(); exit(1); } treeFile=1; strcpy(treeFileName, argv[i]); } else if (*P=='-' && toupper(*(P+1))=='X') { P++; P++; if (*P=='\0') { i++; P = argv[i]; } textFile=1; strcpy(textFileName, P); } else { P++; ch=toupper(*P); P++; switch (ch) { case 'H': // already delt with break; case 'M': // already delt with if (modelTwoArgs) { // the model took two arguments so skip the second one. i++; } break; case 'L': if (GetIntParams(argc, argv, &i, P, 1, &numSites) || numSites<1) { fprintf(stderr, "Bad (or missing) sequence length: %s\n\n", argv[i]); exit(1); } break; case 'N': if (GetIntParams(argc, argv, &i, P, 1, &numDatasets) || numDatasets<1) { fprintf(stderr, "Bad (or missing) number of datasets: %s\n\n", argv[i]); exit(1); } break; case 'P': if (GetIntParams(argc, argv, &i, P, 1, &maxPartitions) || maxPartitions < 1) { fprintf(stderr, "Bad number of partitions: %s\n\n", argv[i]); exit(1); } break; case 'C': if (!isNucModel) { fprintf(stderr, "You can only have codon rates when using nucleotide models\n\n"); exit(1); } if (rateHetero==GammaRates) { fprintf(stderr, "You can only have codon rates or gamma rates not both\n\n"); exit(1); } numCats=3; rateHetero=CodonRates; if (GetDoubleParams(argc, argv, &i, P, 3, catRate) || catRate[0] <= 0.0 || catRate[1] <= 0.0 || catRate[2] <= 0.0 ) { fprintf(stderr, "Bad Category Rates: %s\n\n", argv[i]); exit(1); } break; case 'I': if (GetDoubleParams(argc, argv, &i, P, 1, &proportionInvariable) || proportionInvariable < 0.0 || proportionInvariable >= 1.0) { fprintf(stderr, "Bad Proportion of Invariable Sites: %s\n\n", argv[i]); exit(1); } invariableSites = 1; break; case 'A': if (rateHetero==CodonRates) { fprintf(stderr, "You can only have codon rates or gamma rates not both\n\n"); exit(1); } if (rateHetero==NoRates) rateHetero=GammaRates; if (GetDoubleParams(argc, argv, &i, P, 1, &gammaShape) || gammaShape<=0.0) { fprintf(stderr, "Bad Gamma Shape: %s\n\n", argv[i]); exit(1); } break; case 'G': if (rateHetero==CodonRates) { fprintf(stderr, "You can only have codon rates or gamma rates not both\n\n"); exit(1); } rateHetero=DiscreteGammaRates; if (GetIntParams(argc, argv, &i, P, 1, &numCats) || numCats<2 || numCats>MAX_RATE_CATS) { fprintf(stderr, "Bad number of Gamma Categories: %s\n\n", argv[i]); exit(1); } break; case 'F': if (isNucModel) { if (toupper(*P)=='E'){ /* do nothing - equal freqs is default for nucleotides */ } else { equalFreqs = 0; if (GetDoubleParams(argc, argv, &i, P, NUM_NUC, nucFreq)) { fprintf(stderr, "Bad Nucleotide Frequencies: %s\n\n", argv[i]); exit(1); } } } else { aaFreqSet = 1; if (toupper(*P)=='E'){ equalFreqs = 1; for(j=0;j<NUM_AA;j++) { aaFreq[j]=0.05; } } else { equalFreqs = 0; if (GetDoubleParams(argc, argv, &i, P, NUM_AA, aaFreq)) { fprintf(stderr, "Bad Amino Acid Frequencies: %s\n\n", argv[i]); exit(1); } } } break; case 'T': if (model != HKY && model != F84) { fprintf(stderr, "You can only have a transition/transversion ratio when using HKY or F84 models\n\n"); exit(1); } equalTstv = 0; if (GetDoubleParams(argc, argv, &i, P, 1, &tstv)) { fprintf(stderr, "Bad Transition-Transversion Ratio: %s\n\n", argv[i]); exit(1); } break; case 'R': if (model == GTR) { if (GetDoubleParams(argc, argv, &i, P, NUM_NUC_REL_RATES, nucRelativeRates)) { fprintf(stderr, "Bad General Nucleotide Rate Matrix: %s\n\n", argv[i]); exit(1); } if (nucRelativeRates[NUM_NUC_REL_RATES - 1]!=1.0) { for (j=0; j < NUM_NUC_REL_RATES - 1; j++) nucRelativeRates[j] /= nucRelativeRates[NUM_NUC_REL_RATES - 1]; nucRelativeRates[NUM_NUC_REL_RATES - 1] = 1.0; } } else if ( model == GENERAL) { if (GetDoubleParams(argc, argv, &i, P, NUM_AA_REL_RATES, aaRelativeRate)) { fprintf(stderr, "Bad General Amino Acid Rate Matrix: %s\n\n", argv[i]); exit(1); } } else { fprintf(stderr, "You can only have a general rate matrix when using GTR or GENERAL models\n\n"); exit(1); } break; case 'D': scaleTrees=1; if (GetDoubleParams(argc, argv, &i, P, 1, &treeScale) || treeScale<=0.0) { fprintf(stderr, "Bad Total Tree Scale: %s\n\n", argv[i]); exit(1); } if (scaleBranches) { fprintf(stderr, "You can't specify both the -d and -s options\n\n"); exit(1); } break; case 'S': scaleBranches=1; if (GetDoubleParams(argc, argv, &i, P, 1, &branchScale) || branchScale<=0.0) { fprintf(stderr, "Bad Branch Length Scale: %s\n\n", argv[i]); exit(1); } if (scaleTrees) { fprintf(stderr, "You can't specify both the -d and -s options\n\n"); exit(1); } break; case 'K': if (GetIntParams(argc, argv, &i, P, 1, &ancestorSeq) || ancestorSeq<1) { fprintf(stderr, "Bad ancestral sequence number: %s\n\n", argv[i]); exit(1); } break; case 'Z': userSeed = 1; if (GetUnsignedLongParams(argc, argv, &i, P, 1, &randomSeed)) { fprintf(stderr, "Bad random number generator seed: %s\n\n", argv[i]); exit(1); } break; case 'O': switch (toupper(*P)) { case 'P': fileFormat=PHYLIPFormat; break; case 'R': fileFormat=RelaxedFormat; break; case 'N': fileFormat=NEXUSFormat; break; case 'F': fileFormat=FASTAFormat; break; default: fprintf(stderr, "Unknown output format: %s\n\n", argv[i]); PrintUsage(); exit(1); } break; case 'W': switch (toupper(*P)) { case 'A': writeAncestors=1; break; case 'R': writeRates=1; break; default: fprintf(stderr, "Unknown write mode: %s\n\n", argv[i]); PrintUsage(); exit(1); } break; case 'Q': quiet=1; break; default: fprintf(stderr, "Illegal command parameter: %s\n\n", argv[i]); PrintUsage(); exit(1); break; } } } }