X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=parsefastaqcommand.cpp;h=89f97acf13ad45650a1f8294a3e88895beaa347c;hb=eb71e28b7b7afd82540f4a8f0bac9429c5b9d713;hp=06ea359e6740bd822691e9f8ab6e3e53454cc724;hpb=bdd77df6a7df8a5775b57d0a7ec8b55de45e7b5b;p=mothur.git diff --git a/parsefastaqcommand.cpp b/parsefastaqcommand.cpp index 06ea359..89f97ac 100644 --- a/parsefastaqcommand.cpp +++ b/parsefastaqcommand.cpp @@ -13,11 +13,12 @@ //********************************************************************************************************************** vector ParseFastaQCommand::setParameters(){ try { - CommandParameter pfastq("fastq", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfastq); - CommandParameter pfasta("fasta", "Bool", "", "T", "", "", "",false,false); parameters.push_back(pfasta); - CommandParameter pqual("qfile", "Bool", "", "T", "", "", "",false,false); parameters.push_back(pqual); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfastq("fastq", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pfastq); + CommandParameter pfasta("fasta", "Boolean", "", "T", "", "", "","fasta",false,false); parameters.push_back(pfasta); + CommandParameter pqual("qfile", "Boolean", "", "T", "", "", "","qfile",false,false); parameters.push_back(pqual); + CommandParameter pformat("format", "Multiple", "sanger-illumina-solexa-illumina1.8+", "sanger", "", "", "","",false,false,true); parameters.push_back(pformat); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -33,8 +34,9 @@ string ParseFastaQCommand::getHelpString(){ try { string helpString = ""; helpString += "The fastq.info command reads a fastq file and creates a fasta and quality file.\n"; - helpString += "The fastq.info command parameters are fastq, fasta and qfile; fastq is required.\n"; - helpString += "The fastq.info command should be in the following format: fastq.info(fastaq=yourFastaQFile).\n"; + helpString += "The fastq.info command parameters are fastq, fasta, qfile and format; fastq is required.\n"; + helpString += "The fastq.info command should be in the following format: fastq.info(fastaq=yourFastaQFile).\n"; + helpString += "The format parameter is used to indicate whether your sequences are sanger, solexa, illumina1.8+ or illumina, default=sanger.\n"; helpString += "The fasta parameter allows you to indicate whether you want a fasta file generated. Default=T.\n"; helpString += "The qfile parameter allows you to indicate whether you want a quality file generated. Default=T.\n"; helpString += "Example fastq.info(fastaq=test.fastaq).\n"; @@ -47,6 +49,22 @@ string ParseFastaQCommand::getHelpString(){ } } //********************************************************************************************************************** +string ParseFastaQCommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "fasta") { pattern = "[filename],fasta"; } + else if (type == "qfile") { pattern = "[filename],qual"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ParseFastaQCommand", "getOutputPattern"); + exit(1); + } +} +//********************************************************************************************************************** ParseFastaQCommand::ParseFastaQCommand(){ try { abort = true; calledHelp = true; @@ -116,6 +134,13 @@ ParseFastaQCommand::ParseFastaQCommand(string option){ temp = validParameter.validFile(parameters, "qfile", false); if(temp == "not found"){ temp = "T"; } qual = m->isTrue(temp); + format = validParameter.validFile(parameters, "format", false); if (format == "not found"){ format = "sanger"; } + + if ((format != "sanger") && (format != "illumina") && (format != "illumina1.8+") && (format != "solexa")) { + m->mothurOut(format + " is not a valid format. Your format choices are sanger, solexa, illumina1.8+ and illumina, aborting." ); m->mothurOutEndLine(); + abort=true; + } + if ((!fasta) && (!qual)) { m->mothurOut("[ERROR]: no outputs selected. Aborting."); m->mothurOutEndLine(); abort=true; } } @@ -132,8 +157,10 @@ int ParseFastaQCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //open Output Files - string fastaFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + "fasta"; - string qualFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + "qual"; + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaQFile)); + string fastaFile = getOutputFileName("fasta",variables); + string qualFile = getOutputFileName("qfile",variables); ofstream outFasta, outQual; if (fasta) { m->openOutputFile(fastaFile, outFasta); outputNames.push_back(fastaFile); outputTypes["fasta"].push_back(fastaFile); } @@ -141,6 +168,12 @@ int ParseFastaQCommand::execute(){ ifstream in; m->openInputFile(fastaQFile, in); + + //fill convert table - goes from solexa to sanger. Used fq_all2std.pl as a reference. + for (int i = -64; i < 65; i++) { + char temp = (char) ((int)(33 + 10*log(1+pow(10,(i/10.0)))/log(10)+0.499)); + convertTable.push_back(temp); + } while (!in.eof()) { @@ -216,15 +249,28 @@ vector ParseFastaQCommand::convertQual(string qual) { try { vector qualScores; - int controlChar = int('@'); - + bool negativeScores = false; + for (int i = 0; i < qual.length(); i++) { - int temp = int(qual[i]); - temp -= controlChar; - + + int temp = 0; + temp = int(qual[i]); + if (format == "illumina") { + temp -= 64; //char '@' + }else if (format == "illumina1.8+") { + temp -= int('!'); //char '!' + }else if (format == "solexa") { + temp = int(convertTable[temp]); //convert to sanger + temp -= int('!'); //char '!' + }else { + temp -= int('!'); //char '!' + } + if (temp < -5) { negativeScores = true; } qualScores.push_back(temp); } + if (negativeScores) { m->mothurOut("[ERROR]: finding negative quality scores, do you have the right format selected? http://en.wikipedia.org/wiki/FASTQ_format#Encoding \n"); m->control_pressed = true; } + return qualScores; } catch(exception& e) {