]> git.donarmstrong.com Git - mothur.git/blobdiff - getsabundcommand.cpp
added countable class to read and store count file. added count parameter to make...
[mothur.git] / getsabundcommand.cpp
index 98bdcb2cba6cb726f9d793baca1c78f785a04c00..5425c41a917f4b02d67c5b4dfcb63e1b2fc6159b 100644 (file)
@@ -37,7 +37,7 @@ string GetSAbundCommand::getHelpString(){
                helpString += "Example get.sabund().\n";
                helpString += "The default value for label is all labels in your inputfile.\n";
                helpString += "The get.sabund command outputs a .sabund file containing the labels you selected.\n";
-               helpString += "Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n\n";
+               helpString += "Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n";
                return helpString;
        }
        catch(exception& e) {
@@ -45,7 +45,26 @@ string GetSAbundCommand::getHelpString(){
                exit(1);
        }
 }
-
+//**********************************************************************************************************************
+string GetSAbundCommand::getOutputFileNameTag(string type, string inputName=""){       
+       try {
+        string outputFileName = "";
+               map<string, vector<string> >::iterator it;
+        
+        //is this a type this command creates
+        it = outputTypes.find(type);
+        if (it == outputTypes.end()) {  m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
+        else {
+            if (type == "sabund")            {   outputFileName = "sabund";  }
+            else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true;  }
+        }
+        return outputFileName;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetSAbundCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 GetSAbundCommand::GetSAbundCommand(){  
        try {
@@ -67,6 +86,7 @@ GetSAbundCommand::GetSAbundCommand(string option)  {
                
                //allow user to run help
                if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
                
                else {
                        vector<string> myArray = setParameters();
@@ -113,12 +133,12 @@ GetSAbundCommand::GetSAbundCommand(string option)  {
                        listfile = validParameter.validFile(parameters, "list", true);
                        if (listfile == "not open") { listfile = ""; abort = true; }
                        else if (listfile == "not found") { listfile = ""; }
-                       else {  format = "list"; inputfile = listfile; }
+                       else {  format = "list"; inputfile = listfile; m->setListFile(listfile); }
                        
                        rabundfile = validParameter.validFile(parameters, "rabund", true);
                        if (rabundfile == "not open") { rabundfile = ""; abort = true; }        
                        else if (rabundfile == "not found") { rabundfile = ""; }
-                       else {  format = "rabund"; inputfile = rabundfile; }
+                       else {  format = "rabund"; inputfile = rabundfile; m->setRabundFile(rabundfile); }
                        
                
                                                //check for optional parameter and set defaults
@@ -165,7 +185,7 @@ int GetSAbundCommand::execute(){
        try {
                
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
-               filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "sabund";
+               filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + getOutputFileNameTag("sabund");
                m->openOutputFile(filename, out);
                
                input = new InputData(inputfile, format);
@@ -177,7 +197,7 @@ int GetSAbundCommand::execute(){
                set<string> processedLabels;
                set<string> userLabels = labels;
                
-               if (m->control_pressed) {  outputTypes.clear(); out.close(); remove(filename.c_str());  delete sabund; delete input; return 0; }
+               if (m->control_pressed) {  outputTypes.clear(); out.close(); m->mothurRemove(filename);  delete sabund; delete input; return 0; }
 
                
                while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
@@ -186,9 +206,8 @@ int GetSAbundCommand::execute(){
                                        m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
                                        
                                        sabund->print(out);
-                                       delete sabund;
                                        
-                               if (m->control_pressed) { outputTypes.clear();  out.close(); remove(filename.c_str());  delete sabund; delete input;  return 0; }
+                               if (m->control_pressed) { outputTypes.clear();  out.close(); m->mothurRemove(filename);  delete sabund; delete input;  return 0; }
 
                                        processedLabels.insert(sabund->getLabel());
                                        userLabels.erase(sabund->getLabel());
@@ -202,9 +221,8 @@ int GetSAbundCommand::execute(){
                                        
                                        m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
                                        sabund->print(out);
-                                       delete sabund;
                                        
-                                       if (m->control_pressed) {  outputTypes.clear(); out.close(); remove(filename.c_str());  delete sabund; delete input;  return 0; }
+                                       if (m->control_pressed) {  outputTypes.clear(); out.close(); m->mothurRemove(filename);  delete sabund; delete input;  return 0; }
 
                                        processedLabels.insert(sabund->getLabel());
                                        userLabels.erase(sabund->getLabel());
@@ -242,7 +260,7 @@ int GetSAbundCommand::execute(){
                        sabund->print(out);
                        delete sabund;
                        
-                       if (m->control_pressed) {  outputTypes.clear(); out.close(); remove(filename.c_str());  delete input; return 0; }
+                       if (m->control_pressed) {  outputTypes.clear(); out.close(); m->mothurRemove(filename);  delete input; return 0; }
                        
                }