]> git.donarmstrong.com Git - mothur.git/blobdiff - mergefilecommand.cpp
added pipeline commands which involved change to command factory and command class...
[mothur.git] / mergefilecommand.cpp
index 098da009eaeacfab076c9ad0f800f626158f4a15..d431dd32ff17dcef5e267b1e93a47c8fc93b324b 100644 (file)
@@ -9,6 +9,53 @@
 
 #include "mergefilecommand.h"
 
+//**********************************************************************************************************************
+vector<string> MergeFileCommand::getValidParameters(){ 
+       try {
+               string Array[] =  {"input", "output","outputdir","inputdir"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MergeFileCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+MergeFileCommand::MergeFileCommand(){  
+       try {
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["merge"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MergeFileCommand", "MergeFileCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> MergeFileCommand::getRequiredParameters(){      
+       try {
+               string Array[] =  {"input","output"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MergeFileCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> MergeFileCommand::getRequiredFiles(){   
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "MergeFileCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 
 MergeFileCommand::MergeFileCommand(string option)  {
@@ -34,6 +81,10 @@ MergeFileCommand::MergeFileCommand(string option)  {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["merge"] = 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 = "";          }
@@ -67,7 +118,7 @@ MergeFileCommand::MergeFileCommand(string option)  {
                        
                        outputFileName = validParameter.validFile(parameters, "output", false);                 
                        if (outputFileName == "not found") { m->mothurOut("you must enter an output file name"); m->mothurOutEndLine();  abort=true;  }
-                       else if (outputDir != "") { outputFileName = outputDir + m->getSimpleName(outputFileName); }
+                       else if (outputDir != "") { outputFileName = outputDir + m->getSimpleName(outputFileName);  }
                }
                        
        }
@@ -97,7 +148,7 @@ int MergeFileCommand::execute(){
                        m->openInputFile(fileNames[i], inputFile);
                        
                        while(!inputFile.eof()){        
-                               if (m->control_pressed) { inputFile.close(); outputFile.close(); remove(outputFileName.c_str()); return 0;  }
+                               if (m->control_pressed) { outputTypes.clear(); inputFile.close(); outputFile.close(); remove(outputFileName.c_str()); return 0;  }
                        
                                c = inputFile.get(); 
                                //-1 is eof char
@@ -109,11 +160,11 @@ int MergeFileCommand::execute(){
                
                outputFile.close();
                
-               if (m->control_pressed) { remove(outputFileName.c_str()); return 0;  }
+               if (m->control_pressed) { outputTypes.clear();  remove(outputFileName.c_str()); return 0;  }
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
-               m->mothurOut(outputFileName); m->mothurOutEndLine();    
+               m->mothurOut(outputFileName); m->mothurOutEndLine();    outputNames.push_back(outputFileName); outputTypes["merge"].push_back(outputFileName);
                m->mothurOutEndLine();
 
                return 0;