]> git.donarmstrong.com Git - mothur.git/blobdiff - getgroupcommand.cpp
added weightedlinkage.cpp
[mothur.git] / getgroupcommand.cpp
index 4fa84136001aefaeb051ee592a41e54b081b0885..817331f8ce06a531c447896707951b2e6ffb7b9d 100644 (file)
@@ -10,7 +10,7 @@
 #include "getgroupcommand.h"
 
 //**********************************************************************************************************************
-GetgroupCommand::GetgroupCommand(string option){
+GetgroupCommand::GetgroupCommand(string option)  {
        try {
                globaldata = GlobalData::getInstance();
                abort = false;
@@ -19,9 +19,23 @@ GetgroupCommand::GetgroupCommand(string option){
                if(option == "help") { help(); abort = true; }
                
                else {
-                       if (option != "") { cout << "There are no valid parameters for the get.group command." << endl; abort = true; }
+                       //valid paramters for this command
+                       string Array[] =  {"outputdir","inputdir"};
+                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       if ((globaldata->getSharedFile() == "")) { cout << "You must use the read.otu command to read a groupfile or a sharedfile before you can use the get.group command." << endl; abort = true; }
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
+                       //check to make sure all parameters are valid for command
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       }
+                       
+                       //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 = "";         }
+                       
+                       if ((globaldata->getSharedFile() == "")) { m->mothurOut("You must use the read.otu command to read a groupfile or a sharedfile before you can use the get.group command."); m->mothurOutEndLine(); abort = true; }
                                
                        if (abort == false) {
                                //open shared file
@@ -29,42 +43,34 @@ GetgroupCommand::GetgroupCommand(string option){
                                openInputFile(sharedfile, in);
                
                                //open output file
-                               outputFile = getRootName(sharedfile) + "bootGroups";
+                               if (outputDir == "") { outputDir += hasPath(sharedfile); }
+                               outputFile = outputDir + getRootName(getSimpleName(sharedfile)) + "bootGroups";
                                openOutputFile(outputFile, out);
 
                        }
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function GetgroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "GetgroupCommand", "GetgroupCommand");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the GetgroupCommand class function GetgroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
-                       
 }
 //**********************************************************************************************************************
 
 void GetgroupCommand::help(){
        try {
-               cout << "The get.group command can only be executed after a successful read.otu command." << "\n";
-               //cout << "The get.group command outputs a .bootGroups file to you can use in addition to the tree file generated by the bootstrap.shared command to run the concensus command." << "\n";
-               cout << "You may not use any parameters with the get.group command." << "\n";
-               cout << "The get.group command should be in the following format: " << "\n";
-               cout << "get.group()" << "\n";
-               cout << "Example get.group()." << "\n";
+               m->mothurOut("The get.group command can only be executed after a successful read.otu command.\n");
+               //m->mothurOut("The get.group command outputs a .bootGroups file to you can use in addition to the tree file generated by the bootstrap.shared command to run the consensus command.\n");
+               m->mothurOut("You may not use any parameters with the get.group command.\n");
+               m->mothurOut("The get.group command should be in the following format: \n");
+               m->mothurOut("get.group()\n");
+               m->mothurOut("Example get.group().\n");
                
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "GetgroupCommand", "help");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the GetgroupCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 //**********************************************************************************************************************
@@ -88,7 +94,7 @@ int GetgroupCommand::execute(){
                holdLabel = label;
                
                //output first group
-               cout << groupN << endl;
+               m->mothurOut(groupN); m->mothurOutEndLine();
                out << groupN << '\t' << groupN << endl;        
                        
                //get rest of line
@@ -96,15 +102,19 @@ int GetgroupCommand::execute(){
                        in >> inputData;
                }
                
+               if (m->control_pressed) { 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; }
+                       
                        in >> groupN >> num;
                        count++;
                        
                        //output next group
-                       cout << groupN << endl;
+                       m->mothurOut(groupN); m->mothurOutEndLine();
                        out << groupN << '\t' << groupN << endl;                                
                        
                        //fill vector.  
@@ -117,17 +127,21 @@ int GetgroupCommand::execute(){
                
                in.close();
                out.close();
+               
+               if (m->control_pressed) {  remove(outputFile.c_str());   return 0; }
+               
+               m->mothurOutEndLine();
+               m->mothurOut("Output File Name: "); m->mothurOutEndLine();
+               m->mothurOut(outputFile); m->mothurOutEndLine();        
+               m->mothurOutEndLine();
+               
                return 0;       
        }
 
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "GetgroupCommand", "execute");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the GetgroupCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }