]> git.donarmstrong.com Git - mothur.git/blobdiff - getgroupcommand.cpp
fixed splash page citation
[mothur.git] / getgroupcommand.cpp
index 4d439592127e53ff8b61fc465ef5e27db238e49e..9014031d5a58556493b712282fbf4bfc5535d5e2 100644 (file)
@@ -9,28 +9,53 @@
 
 #include "getgroupcommand.h"
 
-
-GetgroupCommand::GetgroupCommand(){
+//**********************************************************************************************************************
+GetgroupCommand::GetgroupCommand(string option){
        try {
                globaldata = GlobalData::getInstance();
+               abort = false;
                
-               //open shared file
-               sharedfile = globaldata->getSharedFile();
-               openInputFile(sharedfile, in);
+               //allow user to run help
+               if(option == "help") { help(); abort = true; }
                
-               //open output file
-               outputFile = getRootName(globaldata->inputFileName) + "bootGroups";
-               openOutputFile(outputFile, out);
+               else {
+                       if (option != "") { mothurOut("There are no valid parameters for the get.group command."); mothurOutEndLine(); abort = true; }
+                       
+                       if ((globaldata->getSharedFile() == "")) { mothurOut("You must use the read.otu command to read a groupfile or a sharedfile before you can use the get.group command."); mothurOutEndLine(); abort = true; }
+                               
+                       if (abort == false) {
+                               //open shared file
+                               sharedfile = globaldata->getSharedFile();
+                               openInputFile(sharedfile, in);
+               
+                               //open output file
+                               outputFile = getRootName(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";
+               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";
+}
+//**********************************************************************************************************************
+
+void GetgroupCommand::help(){
+       try {
+               mothurOut("The get.group command can only be executed after a successful read.otu command.\n");
+               //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");
+               mothurOut("You may not use any parameters with the get.group command.\n");
+               mothurOut("The get.group command should be in the following format: \n");
+               mothurOut("get.group()\n");
+               mothurOut("Example get.group().\n");
+               
+       }
+       catch(exception& e) {
+               errorOut(e, "GetgroupCommand", "help");
                exit(1);
-       }       
-                       
+       }
 }
 
 //**********************************************************************************************************************
@@ -42,6 +67,9 @@ GetgroupCommand::~GetgroupCommand(){
 
 int GetgroupCommand::execute(){
        try {
+       
+               if (abort == true) { return 0; }
+       
                int num, inputData, count;
                count = 0;  
                string holdLabel, nextLabel, groupN, label;
@@ -51,7 +79,7 @@ int GetgroupCommand::execute(){
                holdLabel = label;
                
                //output first group
-               cout << groupN << endl;
+               mothurOut(groupN); mothurOutEndLine();
                out << groupN << '\t' << groupN << endl;        
                        
                //get rest of line
@@ -67,7 +95,7 @@ int GetgroupCommand::execute(){
                        count++;
                        
                        //output next group
-                       cout << groupN << endl;
+                       mothurOut(groupN); mothurOutEndLine();
                        out << groupN << '\t' << groupN << endl;                                
                        
                        //fill vector.  
@@ -78,18 +106,15 @@ int GetgroupCommand::execute(){
                        if (in.eof() != true) { in >> nextLabel; }
                }
                
+               in.close();
                out.close();
                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";
+               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);
-       }       
 }