]> git.donarmstrong.com Git - mothur.git/blobdiff - parsefastaqcommand.cpp
added template=self capability to chimers.slayer, worked on corr.axes and added accno...
[mothur.git] / parsefastaqcommand.cpp
index 2dece317d758514581ce5e82fc73c16f18afb38f..f0a7abcc3692b8e290863a71c93bcc1831e87fca 100644 (file)
 #include "parsefastaqcommand.h"
 #include "sequence.hpp"
 
+//**********************************************************************************************************************
+vector<string> ParseFastaQCommand::getValidParameters(){       
+       try {
+               string Array[] =  {"fastq", "outputdir","inputdir"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ParseFastaQCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+ParseFastaQCommand::ParseFastaQCommand(){      
+       try {
+               abort = true;
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["fasta"] = tempOutNames;
+               outputTypes["qual"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ParseFastaQCommand", "ParseFastaQCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> ParseFastaQCommand::getRequiredParameters(){    
+       try {
+               string Array[] =  {"fastq"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ParseFastaQCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> ParseFastaQCommand::getRequiredFiles(){ 
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ParseFastaQCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 ParseFastaQCommand::ParseFastaQCommand(string option){
        try {
@@ -19,7 +68,7 @@ ParseFastaQCommand::ParseFastaQCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fastaq", "outputdir", "inputdir"};
+                       string Array[] =  {"fastq", "outputdir", "inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -33,23 +82,28 @@ ParseFastaQCommand::ParseFastaQCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["fasta"] = tempOutNames;
+                       outputTypes["qual"] = tempOutNames;
+                       
                        //if the user changes the input directory command factory will send this info to us in the output parameter 
                        string inputDir = validParameter.validFile(parameters, "inputdir", false);              
                        if (inputDir == "not found"){   inputDir = "";          }
                        else {
                                string path;
-                               it = parameters.find("fastaq");
+                               it = parameters.find("fastq");
                                //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["fastaq"] = inputDir + it->second;           }
+                                       if (path == "") {       parameters["fastq"] = inputDir + it->second;            }
                                }
                        }
                        
                        //check for required parameters
-                       fastaQFile = validParameter.validFile(parameters, "fastaq", true);
-                       if (fastaQFile == "not found") {        m->mothurOut("fastaq is a required parameter for the parse.fastaq command.");   m->mothurOutEndLine();  abort = true;   }
+                       fastaQFile = validParameter.validFile(parameters, "fastq", true);
+                       if (fastaQFile == "not found") {        m->mothurOut("fastq is a required parameter for the fastq.info command.");      m->mothurOutEndLine();  abort = true;   }
                        else if (fastaQFile == "not open")      {       fastaQFile = ""; abort = true;  }       
                        
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
@@ -66,11 +120,11 @@ ParseFastaQCommand::ParseFastaQCommand(string option){
 
 void ParseFastaQCommand::help(){
        try {
-               m->mothurOut("The parse.fastaq command reads a fastaQ file and creates a fasta and quality file.\n");
-               m->mothurOut("The parse.fastaq command parameter is fastaq, and it is required.\n");
-               m->mothurOut("The parse.fastaq command should be in the following format: parse.fastaq(fastaq=yourFastaQFile).\n");
-               m->mothurOut("Example parse.fastaq(fastaq=test.fastaq).\n");
-               m->mothurOut("Note: No spaces between parameter labels (i.e. fastaq), '=' and yourFastaQFile.\n");
+               m->mothurOut("The fastq.info command reads a fastq file and creates a fasta and quality file.\n");
+               m->mothurOut("The fastq.info command parameter is fastq, and it is required.\n");
+               m->mothurOut("The fastq.info command should be in the following format: fastq.info(fastaq=yourFastaQFile).\n");
+               m->mothurOut("Example fastq.info(fastaq=test.fastaq).\n");
+               m->mothurOut("Note: No spaces between parameter labels (i.e. fastq), '=' and yourFastQFile.\n");
                m->mothurOutEndLine();
        }
        catch(exception& e) {
@@ -92,8 +146,8 @@ int ParseFastaQCommand::execute(){
                string fastaFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + "fasta";
                string qualFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + "qual";
                ofstream outFasta, outQual;
-               m->openOutputFile(fastaFile, outFasta);  outputNames.push_back(fastaFile);
-               m->openOutputFile(qualFile, outQual);   outputNames.push_back(qualFile);
+               m->openOutputFile(fastaFile, outFasta);  outputNames.push_back(fastaFile); outputTypes["fasta"].push_back(fastaFile);
+               m->openOutputFile(qualFile, outQual);   outputNames.push_back(qualFile);  outputTypes["qual"].push_back(qualFile);
                
                ifstream in;
                m->openInputFile(fastaQFile, in);
@@ -121,7 +175,7 @@ int ParseFastaQCommand::execute(){
                        if (qual == "") {  m->mothurOut("[ERROR]: missing quality for " + name2); m->mothurOutEndLine(); m->control_pressed = true; break; }
                        
                        //sanity check sequence length and number of quality scores match
-                       if (name != name2) { m->mothurOut("[ERROR]: names do not match. read " + name + " for fasta and " + name2 + " for quality."); m->mothurOutEndLine(); m->control_pressed = true; break; }
+                       if (name2 != "") { if (name != name2) { m->mothurOut("[ERROR]: names do not match. read " + name + " for fasta and " + name2 + " for quality."); m->mothurOutEndLine(); m->control_pressed = true; break; } }
                        if (qual.length() != sequence.length()) { m->mothurOut("[ERROR]: lengths do not match. read " + toString(sequence.length()) + " characters for fasta and " + toString(qual.length()) + " characters for quality scores."); m->mothurOutEndLine(); m->control_pressed = true; break; }
                        
                        //convert quality scores
@@ -139,7 +193,7 @@ int ParseFastaQCommand::execute(){
                outFasta.close();
                outQual.close();
                
-               if (m->control_pressed) { remove(fastaFile.c_str()); remove(qualFile.c_str()); return 0; }
+               if (m->control_pressed) { outputTypes.clear(); remove(fastaFile.c_str()); remove(qualFile.c_str()); return 0; }
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();