void Options::parse(int argc, char** argv) { bool isLevelNotSet = true; for (int argx = 1; argx < argc; argx++) { // Handle Starting Level Option if ( strcmp(argv[argx], "--level") == 0 || strcmp(argv[argx], "-l") == 0) { // Confirm that a level number has been provided. if (argx + 1 >= argc || !isPositiveInt(argv[argx + 1])) { die("You must provide a level number."); } // Confirm that the provided level is within range and is thus // valid. startingLevelNum = atoi(argv[++argx]); if (startingLevelNum < 1 || startingLevelNum > LevelManager::GetTotal()) { die("Invalid level."); } isLevelNotSet = false; // Handle Help Flags. } else if ( strcmp(argv[argx], "--help") == 0 || strcmp(argv[argx], "-h") == 0) { showHelp(); // Handle Version Flags. } else if ( strcmp(argv[argx], "--version") == 0 || strcmp(argv[argx], "-v") == 0 ) { showVersion(); // Initial Mode will be the Editor. } else if ( strcmp(argv[argx], "--editor") == 0 || strcmp(argv[argx], "-e") == 0 ) { initialState = EDIT; // Initial Mode will be the Editor. } else if ( strcmp(argv[argx], "--new") == 0 || strcmp(argv[argx], "-n") == 0 ) { createNewLevel = true; } else { die("Unrecognized option: " + std::string(argv[argx])); } } if (initialState == EDIT && isLevelNotSet && !createNewLevel) { die("You must provide a level number to edit or specify -n."); } }
void SimpleVCF::init(const vector<string> & fields, CoreVCF * corevcf_){ //string line){ unresolvedGT=false; homozygousREF=false; heterozygous=false; homozygousALT=false; indexGenotype=-1; indexGenotypeQual=-1; indexDepth=-1; indexPL=-1; typeOfData=1; // fields=allTokens(line,'\t'); // corevcf = corevcf_; int fieldIndex = corevcf->getFieldIndexAndIncrease(); // cerr<<"fieldIndex "<<fieldIndex<<endl; //FORMAT FIELDS rawFormatNames = fields[ corevcf->getFieldIndexINFO()+1 ]; rawFormatValues = fields[fieldIndex]; // cerr<<"rawFormatNames "<<rawFormatNames<<endl; // cerr<<"rawFormatValues "<<rawFormatValues<<endl; formatFieldNames = allTokens(rawFormatNames ,':'); formatFieldValues = allTokens(rawFormatValues,':'); if(rawFormatValues == "./."){ unresolvedGT=true; observedPL=false; observedGL=false; haploidCall=false; }else{ if(formatFieldNames.size() != formatFieldValues.size()){ cerr<<"SimpleVCF: for line "<<vectorToString(fields,"\t")<<" the format field does not have as many fields as the values"<<endl; exit(1); } observedPL=false; observedGL=false; haploidCall=false; for(unsigned int i=0;i<formatFieldNames.size();i++){ // cerr<<"formatFieldNames["<<i<<"] "<<formatFieldNames[i]<<" = "<<formatFieldValues[i]<<endl; if(formatFieldNames[i] == "GT"){ indexGenotype =i; formatFieldGT= formatFieldValues[i]; bool determinedGenotype=false; //Taken from http://www.broadinstitute.org/gatk/guide/topic?name=intro if(formatFieldGT == "./."){ determinedGenotype=true; unresolvedGT=true; } if(formatFieldGT == "0"){ determinedGenotype=true; homozygousREF=true; haploidCall=true; } if(formatFieldGT == "1"){ determinedGenotype=true; homozygousALT=true; haploidCall=true; } if(formatFieldGT == "0/0"){ determinedGenotype=true; homozygousREF=true; } if(formatFieldGT == "0|0"){ determinedGenotype=true; homozygousREF=true; } if(formatFieldGT == "0/1"){ determinedGenotype=true; heterozygous=true; } if(formatFieldGT == "0|1"){ determinedGenotype=true; heterozygous=true; } if(formatFieldGT == "1|0"){ determinedGenotype=true; heterozygous=true; } if(formatFieldGT == "1/1"){ determinedGenotype=true; homozygousALT=true; } if(formatFieldGT == "1|1"){ determinedGenotype=true; homozygousALT=true; } if(formatFieldGT == "1/2"){ determinedGenotype=true; heterozygousALT=true; } //has first alt and second alt if(formatFieldGT == "1|2"){ determinedGenotype=true; heterozygousALT=true; } //has first alt and second alt if(formatFieldGT == "2/1"){ determinedGenotype=true; heterozygousALT=true; } //has first alt and second alt if(formatFieldGT == "2|1"){ determinedGenotype=true; heterozygousALT=true; } //has first alt and second alt if(formatFieldGT == "0|2"){ determinedGenotype=true; heterozygous2ndALT=true; } //has ref and second alt if(formatFieldGT == "0/2"){ determinedGenotype=true; heterozygous2ndALT=true; } //has ref and second alt if(formatFieldGT == "2/0"){ determinedGenotype=true; heterozygous2ndALT=true; } //has ref and second alt if(formatFieldGT == "2|0"){ determinedGenotype=true; heterozygous2ndALT=true; } //has ref and second alt if(formatFieldGT == "2/2"){ determinedGenotype=true; homozygous2ndALT=true; } //twice the second alt if(formatFieldGT == "2|2"){ determinedGenotype=true; homozygous2ndALT=true; } //twice the second alt //for more than 3 if(!determinedGenotype){ vector<string> fieldsOfGT = allTokens(formatFieldGT ,'/'); if(fieldsOfGT.size() == 2){ // int alleleCFirst = destringify<int> (fieldsOfGT[0]); // int alleleC2nd = destringify<int> (fieldsOfGT[1]); if(isPositiveInt(fieldsOfGT[0]) && isPositiveInt(fieldsOfGT[1]) ){ determinedGenotype=true; unresolvedGT=true; } }else{ vector<string> fieldsOfGT = allTokens(formatFieldGT ,'|'); if(fieldsOfGT.size() == 2){ // int alleleCFirst = destringify<int> (fieldsOfGT[0]); // int alleleC2nd = destringify<int> (fieldsOfGT[1]); if(isPositiveInt(fieldsOfGT[0]) && isPositiveInt(fieldsOfGT[1]) ){ determinedGenotype=true; unresolvedGT=true; } }else{ } } } // if(formatFieldGT == "0/3" || // formatFieldGT == "3/3" || // formatFieldGT == "3/3" || // ){ determinedGenotype=true; unresolvedGT=true; if(!determinedGenotype){ cerr<<"SimpleVCF: unable to determine genotype for line "<<vectorToString(fields,"\t")<<" field=#"<<formatFieldGT<<"#"<<endl; exit(1); } continue; } if(formatFieldNames[i] == "GQ"){ if(formatFieldValues[i] == "."){ indexGenotypeQual =i; formatFieldGQ=0.0; }else{ indexGenotypeQual =i; formatFieldGQ=destringify<float>(formatFieldValues[i]); } continue; } if(formatFieldNames[i] == "DP"){ indexDepth =i; formatFieldDP=destringify<int> (formatFieldValues[i]); continue;} if(formatFieldNames[i] == "GL"){ observedGL=true; if(observedPL){ cerr<<"SimpleVCF: cannot observed both GL and PL "<<vectorToString(fields,"\t")<<""<<endl; exit(1); } indexPL = i; formatFieldGL = formatFieldValues[i]; vector<string> glfields = allTokens(formatFieldGL,','); if(glfields.size() == 2){ //haploid calls (e.g. X for a male) if(!haploidCall){ cerr<<"SimpleVCF: cannot observed 2 GL fields for a non-haploid record "<<vectorToString(fields,"\t")<<""<<endl; exit(1); } formatFieldPLHomoRef = int(-10.0*destringify<double>(glfields[0])); formatFieldPLHetero = -1000000; //very unlikely formatFieldPLHomoAlt = int(-10.0*destringify<double>(glfields[1])); }else{ if(glfields.size() == 3){ //biallelic formatFieldPLHomoRef = int(-10.0*destringify<double>(glfields[0])); formatFieldPLHetero = int(-10.0*destringify<double>(glfields[1])); formatFieldPLHomoAlt = int(-10.0*destringify<double>(glfields[2])); }else{ if(glfields.size() == 6){ //triallelic //according to VCF docs it has the following order AA,AB,BB,AC,BC,CC formatFieldPLHomoRef = int(-10.0*destringify<double>(glfields[0])); //r-r formatFieldPLHetero1 = int(-10.0*destringify<double>(glfields[1])); //r-a1 formatFieldPLHomoAlt1 = int(-10.0*destringify<double>(glfields[2])); //a1-a1 formatFieldPLHetero2 = int(-10.0*destringify<double>(glfields[3])); //r-a2 formatFieldPLHetero12 = int(-10.0*destringify<double>(glfields[4])); //a1-a2 formatFieldPLHomoAlt2 = int(-10.0*destringify<double>(glfields[5])); //a2-a2 }else{ cerr<<"SimpleVCF: for line "<<vectorToString(fields,"\t")<<" the GL field does not have 3 or 6 fields"<<endl; exit(1); } } } } if(formatFieldNames[i] == "PL"){ observedPL=true; if(observedGL){ cerr<<"SimpleVCF: cannot observed both GL and PL "<<vectorToString(fields,"\t")<<""<<endl; exit(1); } indexPL = i; if(formatFieldValues[i] == "."){ formatFieldPL = formatFieldValues[i]; unresolvedGT=true; continue; } formatFieldPL = formatFieldValues[i]; vector<string> plfields = allTokens(formatFieldPL,','); if(plfields.size() == 3){ //biallelic formatFieldPLHomoRef = destringify<int>(plfields[0]); formatFieldPLHetero = destringify<int>(plfields[1]); formatFieldPLHomoAlt = destringify<int>(plfields[2]); }else{ if(plfields.size() == 6){ //triallelic //according to VCF docs it has the following order AA,AB,BB,AC,BC,CC formatFieldPLHomoRef = destringify<int>(plfields[0]); //r-r formatFieldPLHetero1 = destringify<int>(plfields[1]); //r-a1 formatFieldPLHomoAlt1 = destringify<int>(plfields[2]); //a1-a1 formatFieldPLHetero2 = destringify<int>(plfields[3]); //r-a2 formatFieldPLHetero12 = destringify<int>(plfields[4]); //a1-a2 formatFieldPLHomoAlt2 = destringify<int>(plfields[5]); //a2-a2 }else{ cerr<<"SimpleVCF: for line "<<vectorToString(fields,"\t")<<" the PL field does not have 3 or 6 fields"<<endl; exit(1); } } continue; } //To uncomment the fields to get these fields if(formatFieldNames[i] == "A"){ vector<string> adfield = allTokens( formatFieldValues[i] ,','); for(unsigned int j=0;j<adfield.size();j++){ countA.push_back( destringify<int>( adfield[j]) ); } continue; } if(formatFieldNames[i] == "C"){ vector<string> adfield = allTokens( formatFieldValues[i] ,','); for(unsigned int j=0;j<adfield.size();j++){ countC.push_back( destringify<int>( adfield[j]) ); } continue; } if(formatFieldNames[i] == "G"){ vector<string> adfield = allTokens( formatFieldValues[i] ,','); for(unsigned int j=0;j<adfield.size();j++){ countG.push_back( destringify<int>( adfield[j]) ); } continue; } if(formatFieldNames[i] == "T"){ vector<string> adfield = allTokens( formatFieldValues[i] ,','); for(unsigned int j=0;j<adfield.size();j++){ countT.push_back( destringify<int>( adfield[j]) ); } continue; } } } // cout<<getADforA()<<endl; // cout<<getADforC()<<endl; // cout<<getADforG()<<endl; // cout<<getADforT()<<endl; // cerr<<"end"<<endl; }