]> git.donarmstrong.com Git - mothur.git/blobdiff - mergefilecommand.cpp
added namefile to align.check and added seqs from namefile to optimizing piece of...
[mothur.git] / mergefilecommand.cpp
index 7e17b051305014e2aa58831fddfabaad63f319d4..2b34a00b8c3961d581032dcf6b6929404428a3b4 100644 (file)
@@ -9,15 +9,62 @@
 
 #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 {
+               abort = true; calledHelp = true; 
+               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)  {
        try {
-               abort = false;
+               abort = false; calledHelp = false;   
                
                if(option == "help") {
                        help();
-                       abort = true; 
+                       abort = true; calledHelp = true;
                }
                else {
                        //valid paramters for this command
@@ -34,13 +81,17 @@ 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 = "";          }
                        
                        string fileList = validParameter.validFile(parameters, "input", false);                 
                        if(fileList == "not found") { m->mothurOut("you must enter two or more file names"); m->mothurOutEndLine();  abort=true;  }
-                       else{   splitAtDash(fileList, fileNames);       }
+                       else{   m->splitAtDash(fileList, fileNames);    }
                        
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
                        string outputDir = validParameter.validFile(parameters, "outputdir", false);            if (outputDir == "not found")   {       outputDir = "";         }
@@ -55,19 +106,19 @@ MergeFileCommand::MergeFileCommand(string option)  {
                        else{
                                for(int i=0;i<numInputFiles;i++){
                                        if (inputDir != "") {
-                                               string path = hasPath(fileNames[i]);
+                                               string path = m->hasPath(fileNames[i]);
                                                //if the user has not given a path then, add inputdir. else leave path alone.
                                                if (path == "") {       fileNames[i] = inputDir + fileNames[i];         }
                                        }
                                        
-                                       if(openInputFile(fileNames[i], testFile)){      abort = true;   }
+                                       if(m->openInputFile(fileNames[i], testFile)){   abort = true;   }
                                        testFile.close();
                                }
                        }   
                        
                        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 + getSimpleName(outputFileName); }
+                       else if (outputDir != "") { outputFileName = outputDir + m->getSimpleName(outputFileName);  }
                }
                        
        }
@@ -85,18 +136,20 @@ MergeFileCommand::~MergeFileCommand()      {       /*      do nothing      */      }
 
 int MergeFileCommand::execute(){
        try {
-               if (abort == true) {    return 0;       }
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
                ofstream outputFile;
-               openOutputFile(outputFileName, outputFile);
+               m->openOutputFile(outputFileName, outputFile);
                
                char c;
                for(int i=0;i<numInputFiles;i++){
                        ifstream inputFile; //declaration must be inside for loop of windows throws an error
                        
-                       openInputFile(fileNames[i], inputFile);
+                       m->openInputFile(fileNames[i], inputFile);
                        
                        while(!inputFile.eof()){        
+                               if (m->control_pressed) { outputTypes.clear(); inputFile.close(); outputFile.close(); remove(outputFileName.c_str()); return 0;  }
+                       
                                c = inputFile.get(); 
                                //-1 is eof char
                                if (int(c) != -1) { outputFile << c; }   
@@ -107,9 +160,11 @@ int MergeFileCommand::execute(){
                
                outputFile.close();
                
+               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;