]> git.donarmstrong.com Git - mothur.git/blobdiff - clearcutcommand.cpp
mods to trim.seqs
[mothur.git] / clearcutcommand.cpp
index 1a7ab1fcfc3fd51a12a6a13b67b97a5f7aae3388..767981de36e7c3da3063ea4a9b1df696040c0e4f 100644 (file)
@@ -8,16 +8,68 @@
  */
 
 #include "clearcutcommand.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
 #include "clearcut.h"
-
-
+#ifdef __cplusplus
+}
+#endif
+//**********************************************************************************************************************
+vector<string> ClearcutCommand::getValidParameters(){  
+       try {
+               string AlignArray[] =  {"fasta","phylip","version","verbose","quiet","seed","norandom","shuffle","neighbor","expblen",
+                                                               "expdist","ntrees","matrixout","stdout","kimura","jukes","protein","DNA","outputdir","inputdir"};
+               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClearcutCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+ClearcutCommand::ClearcutCommand(){    
+       try {
+               abort = true; calledHelp = true; 
+               vector<string> tempOutNames;
+               outputTypes["tree"] = tempOutNames;
+               outputTypes["matrixout"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClearcutCommand", "ClearcutCommand");
+               exit(1);
+       }
+}//**********************************************************************************************************************
+vector<string> ClearcutCommand::getRequiredParameters(){       
+       try {
+               string Array[] =  {"fasta","phylip","or"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClearcutCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> ClearcutCommand::getRequiredFiles(){    
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClearcutCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 /**************************************************************************************/
 ClearcutCommand::ClearcutCommand(string option)  {     
        try {
-               abort = false;
+               abort = false; calledHelp = false;   
                
                //allow user to run help
-               if(option == "help") { help(); abort = true; }
+               if(option == "help") { help(); abort = true; calledHelp = true; }
                
                else {
                        //valid paramters for this command
@@ -36,6 +88,11 @@ ClearcutCommand::ClearcutCommand(string option)  {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["tree"] = tempOutNames;
+                       outputTypes["matrixout"] = 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 = "";          }
@@ -173,14 +230,17 @@ void ClearcutCommand::help(){
 int ClearcutCommand::execute() {       
        try {
                
-               if (abort == true) { return 0; }
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
                //prepare filename
                string outputName = outputDir + m->getRootName(m->getSimpleName(inputFile)) + "tre";
+               outputNames.push_back(outputName); outputTypes["tree"].push_back(outputName);
                
                vector<char*> cPara;
                
-               char* tempClearcut = new char[8];  strcpy(tempClearcut, "clearcut");  cPara.push_back(tempClearcut);
+               char* tempClearcut = new char[8];  
+               strcpy(tempClearcut, "clearcut"); 
+               cPara.push_back(tempClearcut);
                                
                //you gave us a distance matrix
                if (phylipfile != "") {  char* temp = new char[10];  strcpy(temp, "--distance");  cPara.push_back(temp);        }
@@ -224,6 +284,8 @@ int ClearcutCommand::execute() {
                        char* temp = new char[tempMatrix.length()];
                        strcpy(temp, tempMatrix.c_str());
                        cPara.push_back(temp);
+                       outputNames.push_back((outputDir + matrixout));
+                       outputTypes["matrixout"].push_back((outputDir + matrixout));
                }
 
                if (ntrees != "1")              {  
@@ -250,8 +312,7 @@ int ClearcutCommand::execute() {
                if (!stdoutWanted) {    
                        m->mothurOutEndLine();
                        m->mothurOut("Output File Names: "); m->mothurOutEndLine();
-                       m->mothurOut(outputName); m->mothurOutEndLine();
-                       if (matrixout != "")    {  m->mothurOut(outputDir+matrixout); m->mothurOutEndLine();  }
+                       for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
                        m->mothurOutEndLine();
                }