]> git.donarmstrong.com Git - mothur.git/blobdiff - parsefastaqcommand.cpp
rewrote metastats command in c++, added mothurRemove function to handle ~ error....
[mothur.git] / parsefastaqcommand.cpp
index 7f4fbbab1096101aa8f09931e4c9ac40e04052b1..9cba70b9d2772edba281cd5f03459d1fdc32a966 100644 (file)
 #include "sequence.hpp"
 
 //**********************************************************************************************************************
-vector<string> ParseFastaQCommand::getValidParameters(){       
+vector<string> ParseFastaQCommand::setParameters(){    
        try {
-               string Array[] =  {"fastq", "outputdir","inputdir"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               CommandParameter pfastq("fastq", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfastq);
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               
+               vector<string> myArray;
+               for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
                return myArray;
        }
        catch(exception& e) {
-               m->errorOut(e, "ParseFastaQCommand", "getValidParameters");
+               m->errorOut(e, "ParseFastaQCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-ParseFastaQCommand::ParseFastaQCommand(){      
+string ParseFastaQCommand::getHelpString(){    
        try {
-               abort = true; calledHelp = true; 
-               vector<string> tempOutNames;
-               outputTypes["fasta"] = tempOutNames;
-               outputTypes["qual"] = tempOutNames;
+               string helpString = "";
+               helpString += "The fastq.info command reads a fastq file and creates a fasta and quality file.\n";
+               helpString += "The fastq.info command parameter is fastq, and it is required.\n";
+               helpString += "The fastq.info command should be in the following format: fastq.info(fastaq=yourFastaQFile).\n";
+               helpString += "Example fastq.info(fastaq=test.fastaq).\n";
+               helpString += "Note: No spaces between parameter labels (i.e. fastq), '=' and yourFastQFile.\n";
+               return helpString;
        }
        catch(exception& e) {
-               m->errorOut(e, "ParseFastaQCommand", "ParseFastaQCommand");
+               m->errorOut(e, "ParseFastaQCommand", "getHelpString");
                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(){ 
+ParseFastaQCommand::ParseFastaQCommand(){      
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["fasta"] = tempOutNames;
+               outputTypes["qfile"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "ParseFastaQCommand", "getRequiredFiles");
+               m->errorOut(e, "ParseFastaQCommand", "ParseFastaQCommand");
                exit(1);
        }
 }
@@ -64,11 +62,10 @@ ParseFastaQCommand::ParseFastaQCommand(string option){
                abort = false; calledHelp = false;   
                
                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[] =  {"fastq", "outputdir", "inputdir"};
-                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
@@ -84,7 +81,7 @@ ParseFastaQCommand::ParseFastaQCommand(string option){
                        //initialize outputTypes
                        vector<string> tempOutNames;
                        outputTypes["fasta"] = tempOutNames;
-                       outputTypes["qual"] = tempOutNames;
+                       outputTypes["qfile"] = 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);              
@@ -117,26 +114,6 @@ ParseFastaQCommand::ParseFastaQCommand(string option){
 }
 //**********************************************************************************************************************
 
-void ParseFastaQCommand::help(){
-       try {
-               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) {
-               m->errorOut(e, "ParseFastaQCommand", "help");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-
-ParseFastaQCommand::~ParseFastaQCommand()      {       /*      do nothing      */      }
-
-//**********************************************************************************************************************
-
 int ParseFastaQCommand::execute(){
        try {
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
@@ -146,7 +123,7 @@ int ParseFastaQCommand::execute(){
                string qualFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + "qual";
                ofstream outFasta, outQual;
                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);
+               m->openOutputFile(qualFile, outQual);   outputNames.push_back(qualFile);  outputTypes["qfile"].push_back(qualFile);
                
                ifstream in;
                m->openInputFile(fastaQFile, in);
@@ -192,7 +169,19 @@ int ParseFastaQCommand::execute(){
                outFasta.close();
                outQual.close();
                
-               if (m->control_pressed) { outputTypes.clear(); remove(fastaFile.c_str()); remove(qualFile.c_str()); return 0; }
+               if (m->control_pressed) { outputTypes.clear(); m->mothurRemove(fastaFile); m->mothurRemove(qualFile); return 0; }
+               
+               //set fasta file as new current fastafile
+               string current = "";
+               itTypes = outputTypes.find("fasta");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
+               }
+               
+               itTypes = outputTypes.find("qfile");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setQualFile(current); }
+               }               
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();