]> git.donarmstrong.com Git - mothur.git/blobdiff - getlabelcommand.cpp
added homova command
[mothur.git] / getlabelcommand.cpp
index baabc21acbd2182398f85a2bcb47cf18f1c757bb..fe4387aa118487b5e60e120246b746222f93a5da 100644 (file)
@@ -3,30 +3,81 @@
  *  Mothur
  *
  *  Created by Thomas Ryabin on 1/30/09.
- *  Copyright 2009 __MyCompanyName__. All rights reserved.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
  *
  */
 
 #include "getlabelcommand.h"
 
+//**********************************************************************************************************************
+vector<string> GetlabelCommand::getValidParameters(){  
+       try {
+               string Array[] =  {"outputdir","inputdir"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetlabelCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> GetlabelCommand::getRequiredParameters(){       
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetlabelCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> GetlabelCommand::getRequiredFiles(){    
+       try {
+               string Array[] =  {"list","rabund","sabund", "or"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetlabelCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
 
-
-
-
-
-GetlabelCommand::GetlabelCommand(){
+GetlabelCommand::GetlabelCommand(string option)  {
        try {
                globaldata = GlobalData::getInstance();
+               abort = false;
+               
+               //allow user to run help
+               if(option == "help") { help(); abort = true; }
+               
+               else {
+                       if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund or rabund before you can use the get.label command."); m->mothurOutEndLine(); abort = true; }                         
+               }
+
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the GetlabelCommand class Function GetlabelCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "GetlabelCommand", "GetlabelCommand");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the GetlabelCommand class function GetlabelCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+}
+//**********************************************************************************************************************
+
+void GetlabelCommand::help(){
+       try {
+               m->mothurOut("The get.label command can only be executed after a successful read.otu command.\n");
+               m->mothurOut("You may not use any parameters with the get.label command.\n");
+               m->mothurOut("The get.label command should be in the following format: \n");
+               m->mothurOut("get.label()\n");
+               m->mothurOut("Example get.label().\n");
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetlabelCommand", "help");
                exit(1);
-       }       
-                       
+       }
 }
 
 //**********************************************************************************************************************
@@ -38,34 +89,36 @@ GetlabelCommand::~GetlabelCommand(){
 
 int GetlabelCommand::execute(){
        try {
+               
+               if (abort == true) { return 0; }
+               
                filename = globaldata->inputFileName;
                ifstream in;
-               openInputFile(filename, in);
+               m->openInputFile(filename, in);
                string label;
                int numBins = 0;
                int count = -1;
-               while(in.good())
-               {
+               while(in.good()) {
+                       
+                       if (m->control_pressed) { in.close();  return 0; }
+                       
                        if(count > numBins)
                                count = 0;
-                       if(count == 0)
-                       {
-                               cout << label << "\n";
+                       if(count == 0) {
+                               m->mothurOut(label); m->mothurOutEndLine();
                                in >> numBins;
                        }
                        in >> label;
                        count++;
                }       
+               
+               in.close();
                return 0;       
        }
 
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the GetlabelCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "GetlabelCommand", "execute");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the GetlabelCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }