X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=makefastqcommand.cpp;h=5a66d9a4b7b23ccd9051803d0e817fc7cf89f315;hp=c6dcf2c83092303abdd685848efe9c875ca75976;hb=615301e57c25e241356a9c2380648d117709458d;hpb=f687723a8357916e86a05116978e6869b039ce36 diff --git a/makefastqcommand.cpp b/makefastqcommand.cpp index c6dcf2c..5a66d9a 100644 --- a/makefastqcommand.cpp +++ b/makefastqcommand.cpp @@ -14,10 +14,11 @@ //********************************************************************************************************************** vector MakeFastQCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pqfile); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fastq",false,true,true); parameters.push_back(pfasta); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none","fastq",false,true,true); parameters.push_back(pqfile); + CommandParameter pformat("format", "Multiple", "sanger-illumina-illumina1.8+", "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); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -32,9 +33,9 @@ vector MakeFastQCommand::setParameters(){ string MakeFastQCommand::getHelpString(){ try { string helpString = ""; - helpString += "The make.fastq command read a fasta and quality file and creates a fastq file.\n"; - helpString += "The make.fastq command parameters are fasta and qfile, both are required.\n"; - helpString += "You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n"; + helpString += "The make.fastq command reads a fasta and quality file and creates a fastq file.\n"; + helpString += "The make.fastq command parameters are fasta, qfile and format. fasta and qfile are required.\n"; + helpString += "The format parameter is used to indicate whether your sequences are sanger, illumina1.8+ or illumina, default=sanger.\n"; helpString += "The make.fastq command should be in the following format: make.fastq(qfile=yourQualityFile, fasta=yourFasta).\n"; helpString += "Example make.fastq(fasta=amazon.fasta, qfile=amazon.qual).\n"; helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"; @@ -46,24 +47,19 @@ string MakeFastQCommand::getHelpString(){ } } //********************************************************************************************************************** -string MakeFastQCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string MakeFastQCommand::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 == "fastq") { outputFileName = "fastq"; } - 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, "MakeFastQCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fastq") { pattern = "[filename],fastq"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "MakeFastQCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** MakeFastQCommand::MakeFastQCommand(){ @@ -148,6 +144,14 @@ MakeFastQCommand::MakeFastQCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(fastafile); } + + format = validParameter.validFile(parameters, "format", false); if (format == "not found"){ format = "sanger"; } + + if ((format != "sanger") && (format != "illumina") && (format != "illumina1.8+")) { + m->mothurOut(format + " is not a valid format. Your format choices are sanger, illumina1.8+ and illumina, aborting." ); m->mothurOutEndLine(); + abort=true; + } + } @@ -164,8 +168,9 @@ int MakeFastQCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - - string outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fastq"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string outputFile = getOutputFileName("fastq",variables); outputNames.push_back(outputFile); outputTypes["fastq"].push_back(outputFile); ofstream out; @@ -176,7 +181,7 @@ int MakeFastQCommand::execute(){ ifstream fFile; m->openInputFile(fastafile, fFile); - + while (!fFile.eof() && !qFile.eof()) { if (m->control_pressed) { break; } @@ -221,9 +226,10 @@ string MakeFastQCommand::convertQual(vector qual) { try { string qualScores; - int controlChar = int('@'); - - for (int i = 0; i < qual.size(); i++) { + for (int i = 0; i < qual.size(); i++) { + int controlChar = int('!'); + if (format == "illumina") { controlChar = int('@'); } + int temp = qual[i] + controlChar; char qualChar = (char) temp;