]> git.donarmstrong.com Git - mothur.git/blobdiff - getgroupcommand.cpp
working on anosim command
[mothur.git] / getgroupcommand.cpp
index 817331f8ce06a531c447896707951b2e6ffb7b9d..ab3ccfa36f3f2d4e6a7e1f5af6a38434640f3105 100644 (file)
@@ -9,14 +9,61 @@
 
 #include "getgroupcommand.h"
 
+//**********************************************************************************************************************
+vector<string> GetgroupCommand::getValidParameters(){  
+       try {
+               string Array[] =  {"outputdir","inputdir"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetgroupCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+GetgroupCommand::GetgroupCommand(){    
+       try {
+               abort = true; calledHelp = true; 
+               vector<string> tempOutNames;
+               outputTypes["bootgroup"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetgroupCommand", "GetgroupCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> GetgroupCommand::getRequiredParameters(){       
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetgroupCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> GetgroupCommand::getRequiredFiles(){    
+       try {
+               string Array[] =  {"shared"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetgroupCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 GetgroupCommand::GetgroupCommand(string option)  {
        try {
                globaldata = GlobalData::getInstance();
-               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
@@ -32,6 +79,10 @@ GetgroupCommand::GetgroupCommand(string option)  {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["bootgroup"] = tempOutNames;
+                       
                        //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 = "";         }
                        
@@ -40,12 +91,12 @@ GetgroupCommand::GetgroupCommand(string option)  {
                        if (abort == false) {
                                //open shared file
                                sharedfile = globaldata->getSharedFile();
-                               openInputFile(sharedfile, in);
+                               m->openInputFile(sharedfile, in);
                
                                //open output file
-                               if (outputDir == "") { outputDir += hasPath(sharedfile); }
-                               outputFile = outputDir + getRootName(getSimpleName(sharedfile)) + "bootGroups";
-                               openOutputFile(outputFile, out);
+                               if (outputDir == "") { outputDir += m->hasPath(sharedfile); }
+                               outputFile = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "bootGroups";
+                               m->openOutputFile(outputFile, out);
 
                        }
                }
@@ -83,7 +134,7 @@ GetgroupCommand::~GetgroupCommand(){
 int GetgroupCommand::execute(){
        try {
        
-               if (abort == true) { return 0; }
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
        
                int num, inputData, count;
                count = 0;  
@@ -102,13 +153,13 @@ int GetgroupCommand::execute(){
                        in >> inputData;
                }
                
-               if (m->control_pressed) { in.close();  out.close(); remove(outputFile.c_str());   return 0; }
+               if (m->control_pressed) { outputTypes.clear(); in.close();  out.close(); remove(outputFile.c_str());   return 0; }
 
                if (in.eof() != true) { in >> nextLabel; }
                
                //read the rest of the groups info in
                while ((nextLabel == holdLabel) && (in.eof() != true)) {
-                       if (m->control_pressed) { in.close();  out.close(); remove(outputFile.c_str());   return 0; }
+                       if (m->control_pressed) {  outputTypes.clear(); in.close();  out.close(); remove(outputFile.c_str());   return 0; }
                        
                        in >> groupN >> num;
                        count++;
@@ -132,7 +183,7 @@ int GetgroupCommand::execute(){
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
-               m->mothurOut(outputFile); m->mothurOutEndLine();        
+               m->mothurOut(outputFile); m->mothurOutEndLine();        outputNames.push_back(outputFile); outputTypes["bootgroup"].push_back(outputFile);
                m->mothurOutEndLine();
                
                return 0;