]> git.donarmstrong.com Git - mothur.git/blobdiff - getsabundcommand.cpp
Merge remote-tracking branch 'mothur/master'
[mothur.git] / getsabundcommand.cpp
index 3f6413606193afed8b5e2b7f6e89d77c20ef4ce4..237506e666641ab80e263db5573aec13756e3429 100644 (file)
 //**********************************************************************************************************************
 vector<string> GetSAbundCommand::setParameters(){      
        try {
-               CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist);
-               CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund);            
-               CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
-               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
-               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","sabund",false,false, true); parameters.push_back(plist);
+               CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none","sabund",false,false, true); parameters.push_back(prabund);             
+               CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
                
                vector<string> myArray;
                for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
@@ -45,7 +45,21 @@ string GetSAbundCommand::getHelpString(){
                exit(1);
        }
 }
-
+//**********************************************************************************************************************
+string GetSAbundCommand::getOutputPattern(string type) {
+    try {
+        string pattern = "";
+        
+        if (type == "sabund")      {   pattern = "[filename],sabund";    }
+        else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
+        
+        return pattern;
+    }
+    catch(exception& e) {
+        m->errorOut(e, "GetRAbundCommand", "getOutputPattern");
+        exit(1);
+    }
+}
 //**********************************************************************************************************************
 GetSAbundCommand::GetSAbundCommand(){  
        try {
@@ -114,12 +128,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
@@ -166,7 +180,9 @@ int GetSAbundCommand::execute(){
        try {
                
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
-               filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "sabund";
+        map<string, string> variables; 
+               variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile));
+               filename = getOutputFileName("sabund", variables);
                m->openOutputFile(filename, out);
                
                input = new InputData(inputfile, format);
@@ -178,7 +194,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))) {
@@ -188,7 +204,7 @@ int GetSAbundCommand::execute(){
                                        
                                        sabund->print(out);
                                        
-                               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());
@@ -203,7 +219,7 @@ int GetSAbundCommand::execute(){
                                        m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
                                        sabund->print(out);
                                        
-                                       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());
@@ -241,7 +257,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; }
                        
                }
                
@@ -249,7 +265,7 @@ int GetSAbundCommand::execute(){
                delete input;
                
                m->mothurOutEndLine();
-               m->mothurOut("Output File Name: "); m->mothurOutEndLine();
+               m->mothurOut("Output File Names: "); m->mothurOutEndLine();
                m->mothurOut(filename); m->mothurOutEndLine();  outputNames.push_back(filename); outputTypes["sabund"].push_back(filename);
                m->mothurOutEndLine();