X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=parsefastaqcommand.cpp;h=704e752341320dd75b9f213658d74530583ec9cb;hb=5ca84bbe4393adecc30dc05d64e79091ef35c40f;hp=816bdb5d38c53afb849be7d5e65b458ac8582148;hpb=035f86272c776e1cccaa47021e26782e49cd41e7;p=mothur.git diff --git a/parsefastaqcommand.cpp b/parsefastaqcommand.cpp index 816bdb5..704e752 100644 --- a/parsefastaqcommand.cpp +++ b/parsefastaqcommand.cpp @@ -13,12 +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 pformat("format", "Multiple", "sanger-illumina-solexa", "sanger", "", "", "",false,false); parameters.push_back(pformat); - 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); } @@ -36,7 +36,7 @@ string ParseFastaQCommand::getHelpString(){ 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, 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 or illumina, default=sanger.\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"; @@ -49,27 +49,21 @@ string ParseFastaQCommand::getHelpString(){ } } //********************************************************************************************************************** -string ParseFastaQCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ParseFastaQCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //is this a type this command creates - it = outputTypes.find(type); - if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } - else { - if (type == "fasta") { outputFileName = "fasta"; } - else if (type == "qfile") { outputFileName = "qual"; } - else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } - } - return outputFileName; - } - catch(exception& e) { - m->errorOut(e, "ParseFastaQCommand", "getOutputFileNameTag"); - exit(1); - } + 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 { @@ -142,8 +136,8 @@ ParseFastaQCommand::ParseFastaQCommand(string option){ format = validParameter.validFile(parameters, "format", false); if (format == "not found"){ format = "sanger"; } - if ((format != "sanger") && (format != "illumina") && (format != "solexa")) { - m->mothurOut(format + " is not a valid format. Your format choices are sanger, solexa and illumina, aborting." ); m->mothurOutEndLine(); + 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; } @@ -163,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)) + getOutputFileNameTag("fasta"); - string qualFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + getOutputFileNameTag("qfile"); + 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); } @@ -187,7 +183,10 @@ int ParseFastaQCommand::execute(){ string name = m->getline(in); m->gobble(in); if (name == "") { m->mothurOut("[ERROR]: Blank fasta name."); m->mothurOutEndLine(); m->control_pressed = true; break; } else if (name[0] != '@') { m->mothurOut("[ERROR]: reading " + name + " expected a name with @ as a leading character."); m->mothurOutEndLine(); m->control_pressed = true; break; } - else { name = name.substr(1); } + else { + name = name.substr(1); + for (int i = 0; i < name.length(); i++) { if (name[i] == ':') { name[i] = '_'; m->changedSeqNames = true; } } + } //read sequence string sequence = m->getline(in); m->gobble(in); @@ -197,7 +196,10 @@ int ParseFastaQCommand::execute(){ string name2 = m->getline(in); m->gobble(in); if (name2 == "") { m->mothurOut("[ERROR]: Blank quality name."); m->mothurOutEndLine(); m->control_pressed = true; break; } else if (name2[0] != '+') { m->mothurOut("[ERROR]: reading " + name2 + " expected a name with + as a leading character."); m->mothurOutEndLine(); m->control_pressed = true; break; } - else { name2 = name2.substr(1); } + else { + name2 = name2.substr(1); + for (int i = 0; i < name2.length(); i++) { if (name2[i] == ':') { name2[i] = '_'; m->changedSeqNames = true; } } + } //read quality scores string quality = m->getline(in); m->gobble(in); @@ -253,21 +255,28 @@ vector ParseFastaQCommand::convertQual(string qual) { try { vector qualScores; + bool negativeScores = false; + for (int i = 0; i < qual.length(); i++) { 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 -= 33; //char '!' + temp -= int('!'); //char '!' }else { - temp -= 33; //char '!' + 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) {