X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=makefastqcommand.cpp;h=c6dcf2c83092303abdd685848efe9c875ca75976;hb=fdfbfe59134dd7dd3e49d90609d129128ba2d370;hp=3809af2a55e6e959014f271ce1ee642854a336aa;hpb=c67cf4168e1a124088b6f017946f0aa1fbdf1301;p=mothur.git diff --git a/makefastqcommand.cpp b/makefastqcommand.cpp index 3809af2..c6dcf2c 100644 --- a/makefastqcommand.cpp +++ b/makefastqcommand.cpp @@ -12,49 +12,69 @@ #include "qualityscores.h" //********************************************************************************************************************** -vector MakeFastQCommand::getValidParameters(){ +vector MakeFastQCommand::setParameters(){ try { - string Array[] = {"fasta","qfile","outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + 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); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "MakeFastQCommand", "getValidParameters"); + m->errorOut(e, "MakeFastQCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -MakeFastQCommand::MakeFastQCommand(){ +string MakeFastQCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fastq"] = tempOutNames; + 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 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"; + return helpString; } catch(exception& e) { - m->errorOut(e, "MakeFastQCommand", "MakeFastQCommand"); + m->errorOut(e, "MakeFastQCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector MakeFastQCommand::getRequiredParameters(){ +string MakeFastQCommand::getOutputFileNameTag(string type, string inputName=""){ try { - string Array[] = {"fasta","qfile"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string outputFileName = ""; + map >::iterator it; + + //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", "getRequiredParameters"); + m->errorOut(e, "MakeFastQCommand", "getOutputFileNameTag"); exit(1); } } //********************************************************************************************************************** -vector MakeFastQCommand::getRequiredFiles(){ +MakeFastQCommand::MakeFastQCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fastq"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "MakeFastQCommand", "getRequiredFiles"); + m->errorOut(e, "MakeFastQCommand", "MakeFastQCommand"); exit(1); } } @@ -65,11 +85,10 @@ MakeFastQCommand::MakeFastQCommand(string option) { //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { - //valid paramters for this command - string Array[] = {"fasta","qfile", "outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -107,25 +126,25 @@ MakeFastQCommand::MakeFastQCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["qfile"] = inputDir + it->second; } } - - it = parameters.find("list"); - //user has given a template file - if(it != parameters.end()){ - path = m->hasPath(it->second); - //if the user has not given a path then, add inputdir. else leave path alone. - if (path == "") { parameters["list"] = inputDir + it->second; } - } } //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; fastafile = ""; } - else if (fastafile == "not found") { fastafile = ""; m->mothurOut("You must provide a fasta file."); m->mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + }else { m->setFastaFile(fastafile); } qualfile = validParameter.validFile(parameters, "qfile", true); if (qualfile == "not open") { abort = true; qualfile = ""; } - else if (qualfile == "not found") { qualfile = ""; m->mothurOut("You must provide a quality file."); m->mothurOutEndLine(); abort = true; } + else if (qualfile == "not found") { + qualfile = m->getQualFile(); + if (qualfile != "") { m->mothurOut("Using " + qualfile + " as input file for the qfile parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current qualfile and the qfile parameter is required."); m->mothurOutEndLine(); abort = true; } + }else { m->setQualFile(qualfile); } //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); } @@ -140,33 +159,13 @@ MakeFastQCommand::MakeFastQCommand(string option) { } //********************************************************************************************************************** -void MakeFastQCommand::help(){ - try { - /*m->mothurOut("The get.groups command selects sequences from a specfic group or set of groups from the following file types: fasta, name, group, list, taxonomy.\n"); - m->mothurOut("It outputs a file containing the sequences in the those specified groups.\n"); - m->mothurOut("The get.groups command parameters are accnos, fasta, name, group, list, taxonomy and groups. The group parameter is required.\n"); - m->mothurOut("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"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like. You can separate group names with dashes.\n"); - m->mothurOut("The get.groups command should be in the following format: get.groups(accnos=yourAccnos, fasta=yourFasta, group=yourGroupFile).\n"); - m->mothurOut("Example get.seqs(accnos=amazon.accnos, fasta=amazon.fasta, group=amazon.groups).\n"); - m->mothurOut("or get.seqs(groups=pasture, fasta=amazon.fasta, amazon.groups).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");*/ - } - catch(exception& e) { - m->errorOut(e, "MakeFastQCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int MakeFastQCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - string outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "fastq"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fastq"); outputNames.push_back(outputFile); outputTypes["fastq"].push_back(outputFile); ofstream out; @@ -202,7 +201,7 @@ int MakeFastQCommand::execute(){ qFile.close(); out.close(); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -222,7 +221,7 @@ string MakeFastQCommand::convertQual(vector qual) { try { string qualScores; - int controlChar = int('!'); + int controlChar = int('@'); for (int i = 0; i < qual.size(); i++) { int temp = qual[i] + controlChar;