]> git.donarmstrong.com Git - mothur.git/blobdiff - catchallcommand.cpp
changes while testing
[mothur.git] / catchallcommand.cpp
index 69b9f04becdbb492fc69209837be5a0581123b99..a914f733caef6f3535bfe88a4ff532a2989f7971 100644 (file)
@@ -8,70 +8,98 @@
  */
 
 #include "catchallcommand.h"
-#include "globaldata.hpp"
 
 //**********************************************************************************************************************
-vector<string> CatchAllCommand::getValidParameters(){  
+vector<string> CatchAllCommand::setParameters(){       
        try {
-               string AlignArray[] =  {"sabund","shared","label","inputdir","outputdir"};
-               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+               CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
+               //can choose shared or sabund not both, so put them in the same chooseOnlyOneGroup
+               CommandParameter pshared("shared", "InputTypes", "", "", "catchallInputs", "catchallInputs", "none","analysis-bestanalysis-models-bubble-summary",false,false,true); parameters.push_back(pshared);
+               CommandParameter psabund("sabund", "InputTypes", "", "", "catchallInputs", "catchallInputs", "none","analysis-bestanalysis-models-bubble-summary",false,false,true); parameters.push_back(psabund);
+               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);          }
                return myArray;
        }
        catch(exception& e) {
-               m->errorOut(e, "CatchAllCommand", "getValidParameters");
+               m->errorOut(e, "CatchAllCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-CatchAllCommand::CatchAllCommand(){    
+string CatchAllCommand::getHelpString(){       
        try {
-               //initialize outputTypes
-               vector<string> tempOutNames;
-               outputTypes["csv"] = tempOutNames;
-               outputTypes["summary"] = tempOutNames;
+               string helpString = "";
+               helpString += "The catchall command interfaces mothur with the catchall program written by Linda Woodard, Sean Connolly and John Bunge.\n";
+               helpString += "For more information about catchall refer to http://www.northeastern.edu/catchall/index.html \n";
+               helpString += "The catchall executable must be in the same folder as your mothur executable. \n";
+               helpString += "If you are a MAC or Linux user you must also have installed mono, a link to mono is on the webpage. \n";
+               helpString += "The catchall command parameters are shared, sabund and label.  shared or sabund is required. \n";
+               helpString += "The label parameter is used to analyze specific labels in your input.\n";
+               helpString += "The catchall command should be in the following format: \n";
+               helpString += "catchall(sabund=yourSabundFile) \n";
+               helpString += "Example: catchall(sabund=abrecovery.fn.sabund) \n";      
+               return helpString;
        }
        catch(exception& e) {
-               m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
+               m->errorOut(e, "CatchAllCommand", "getHelpString");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> CatchAllCommand::getRequiredParameters(){       
-       try {
-               string AlignArray[] =  {"sabund","shared","or"};
-               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "CatchAllCommand", "getRequiredParameters");
-               exit(1);
-       }
+string CatchAllCommand::getOutputPattern(string type) {
+    try {
+        string pattern = "";
+        
+        if (type == "analysis") {  pattern = "[filename],_Analysis.csv"; } 
+        else if (type == "bestanalysis") {  pattern = "[filename],_BestModelsAnalysis.csv"; }
+        else if (type == "models") {  pattern = "[filename],_BestModelsAnalysis.csv"; }
+        else if (type == "bubble") {  pattern = "[filename],_BubblePlot.csv"; }
+        else if (type == "summary") {  pattern =  "[filename],catchall.summary"; }
+        else if (type == "sabund") {  pattern =  "[filename],[distance],csv"; }
+        else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
+        
+        return pattern;
+    }
+    catch(exception& e) {
+        m->errorOut(e, "CatchAllCommand", "getOutputPattern");
+        exit(1);
+    }
 }
 //**********************************************************************************************************************
-vector<string> CatchAllCommand::getRequiredFiles(){    
+CatchAllCommand::CatchAllCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["analysis"] = tempOutNames;
+               outputTypes["bestanalysis"] = tempOutNames;
+        outputTypes["models"] = tempOutNames;
+               outputTypes["bubble"] = tempOutNames;
+               outputTypes["summary"] = tempOutNames;
+        outputTypes["sabund"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "CatchAllCommand", "getRequiredFiles");
+               m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
                exit(1);
        }
 }
 /**************************************************************************************/
 CatchAllCommand::CatchAllCommand(string option)  {     
        try {
-               globaldata = GlobalData::getInstance();
-               abort = false;
+               
+               abort = false; calledHelp = false;   
                allLines = 1;
                
                //allow user to run help
-               if(option == "help") { help(); abort = true; }
+               if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
                
                else {
-                       //valid paramters for this command
-                       string Array[] =  {"shared","sabund","label","inputdir","outputdir"};
-                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
@@ -86,8 +114,13 @@ CatchAllCommand::CatchAllCommand(string option)  {
                        
                        //initialize outputTypes
                        vector<string> tempOutNames;
-                       outputTypes["csv"] = tempOutNames;
-                       outputTypes["summary"] = tempOutNames;
+                       outputTypes["analysis"] = tempOutNames;
+            outputTypes["bestanalysis"] = tempOutNames;
+            outputTypes["models"] = tempOutNames;
+            outputTypes["bubble"] = tempOutNames;
+            outputTypes["summary"] = tempOutNames;
+            outputTypes["sabund"] = tempOutNames;
+
                        
                        //if the user changes the input directory command factory will send this info to us in the output parameter 
                        string inputDir = validParameter.validFile(parameters, "inputdir", false);              
@@ -115,16 +148,12 @@ CatchAllCommand::CatchAllCommand(string option)  {
                        sabundfile = validParameter.validFile(parameters, "sabund", true);
                        if (sabundfile == "not open") { sabundfile = ""; abort = true; }
                        else if (sabundfile == "not found") { sabundfile = "";  }
-                       else { globaldata->setSabundFile(sabundfile); globaldata->setFormat("sabund"); }
+                       else { m->setSabundFile(sabundfile); }
                        
                        sharedfile = validParameter.validFile(parameters, "shared", true);
                        if (sharedfile == "not open") { sharedfile = ""; abort = true; }
                        else if (sharedfile == "not found") { sharedfile = "";   }
-                       
-                       //check for shared file loaded during read.otu
-                       if (sharedfile == "") {
-                               if (globaldata->getSharedFile() != "") { sharedfile = globaldata->getSharedFile(); }
-                       }
+                       else { m->setSharedFile(sharedfile); }
                        
                        string label = validParameter.validFile(parameters, "label", false);                    
                        if (label == "not found") { label = ""; }
@@ -133,8 +162,22 @@ CatchAllCommand::CatchAllCommand(string option)  {
                                else { allLines = 1;  }
                        }
                
-                       if ((sharedfile == "") && (sabundfile == "")) { m->mothurOut("You must provide a sabund or shared file for the catchall command."); m->mothurOutEndLine(); abort=true; }
-
+                       if ((sharedfile == "") && (sabundfile == "")) { 
+                               //is there are current file available for either of these?
+                               //give priority to shared, then sabund
+                               //if there is a current shared file, use it
+                               sharedfile = m->getSharedFile(); 
+                               if (sharedfile != "") {  m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
+                               else { 
+                                       sabundfile = m->getSabundFile(); 
+                                       if (sabundfile != "") {  m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); }
+                                       else { 
+                                               m->mothurOut("No valid current files. You must provide a sabund or shared file before you can use the catchall command."); m->mothurOutEndLine(); 
+                                               abort = true;
+                                       }
+                               }
+                       }
+                       
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
                        outputDir = validParameter.validFile(parameters, "outputdir", false);           
                        if (outputDir == "not found"){  
@@ -149,50 +192,65 @@ CatchAllCommand::CatchAllCommand(string option)  {
                exit(1);
        }
 }
-//**********************************************************************************************************************
-
-void CatchAllCommand::help(){
-       try {
-               m->mothurOut("The catchall command interfaces mothur with the catchall program written by Linda Woodard, Sean Connolly and John Bunge.\n");
-               m->mothurOut("For more information about catchall refer to http://www.northeastern.edu/catchall/index.html \n");
-               m->mothurOut("The catchall executable must be in the same folder as your mothur executable. \n");
-               m->mothurOut("If you are a MAC or Linux user you must also have installed mono, a link to mono is on the webpage. \n");
-               m->mothurOut("The catchall command parameters are shared, sabund and label.  shared or sabund is required. \n");
-               m->mothurOut("The label parameter is used to analyze specific labels in your input.\n");
-               m->mothurOut("The catchall command should be in the following format: \n");
-               m->mothurOut("catchall(sabund=yourSabundFile) \n");
-               m->mothurOut("Example: catchall(sabund=abrecovery.fn.sabund) \n");      
-       }
-       catch(exception& e) {
-               m->errorOut(e, "CatchAllCommand", "help");
-               exit(1);
-       }
-}
-
 /**************************************************************************************/
 int CatchAllCommand::execute() {       
        try {
                
-               if (abort == true) { return 0; }
-               
-               //prepare full output directory
-               outputDir = m->getFullPathName(outputDir);
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
                //get location of catchall
-               GlobalData* globaldata = GlobalData::getInstance();
-               path = globaldata->argv;
-               path = path.substr(0, (path.find_last_of('m')));
+               path = m->argv;
+               path = path.substr(0, (path.find_last_of("othur")-5));
                path = m->getFullPathName(path);
-
-               string catchAllCommandExe = ""; 
-               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                       catchAllCommandExe += "mono " + path + "CatchAllcmdL.exe ";
+               
+        if (m->debug) { m->mothurOut("[DEBUG]: mothur's path = " + path + "\n"); }
+       
+               savedOutputDir = outputDir;
+               string catchAllCommandExe = "";
+        string catchAllTest = "";
+               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+                       if (outputDir == "") { outputDir = "./"; } //force full pathname to be created for catchall, this is necessary because if catchall is in the path it will look for input file whereever the exe is and not the cwd.
+            catchAllTest = path + "CatchAllcmdL.exe";
                #else
-                       catchAllCommandExe += "\"" + path + "CatchAllcmdW.exe\"" + " ";
+                       if (outputDir == "") { outputDir = ".\\"; } //force full pathname to be created for catchall, this is necessary because if catchall is in the path it will look for input file whereever the exe is and not the cwd.
+            catchAllTest = path + "CatchAllcmdW.exe";
                #endif
                
+        //test to make sure formatdb exists
+               ifstream in;
+               catchAllTest = m->getFullPathName(catchAllTest);
+               int ableToOpen = m->openInputFile(catchAllTest, in, "no error"); in.close();
+               if(ableToOpen == 1) {   
+            m->mothurOut(catchAllTest + " file does not exist. Checking path... \n");
+            //check to see if uchime is in the path??
+            
+            string programName = "CatchAllcmdW.exe";
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+            programName = "CatchAllcmdL.exe";
+#endif
+            string cLocation = m->findProgramPath(programName);
+            
+            ifstream in2;
+            ableToOpen = m->openInputFile(cLocation, in2, "no error"); in2.close();
+
+            if(ableToOpen == 1) { m->mothurOut("[ERROR]: " + cLocation + " file does not exist. mothur requires the catchall executable."); m->mothurOutEndLine();  return 0; } 
+            else {  m->mothurOut("Found catchall in your path, using " + cLocation + "\n"); catchAllTest = cLocation; }
+        }
+        catchAllTest = m->getFullPathName(catchAllTest);
+        
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+        catchAllCommandExe += "mono \"" + catchAllTest + "\" ";
+#else
+        catchAllCommandExe += "\"" + catchAllTest + "\" ";
+#endif
+        
+               //prepare full output directory
+               outputDir = m->getFullPathName(outputDir);
+               
+        if (m->debug) { m->mothurOut("[DEBUG]: catchall location = " + catchAllCommandExe + "\n[DEBUG]: outputDir = " + outputDir + "\n"); }
+        
                vector<string> inputFileNames;
-               if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile);  globaldata->setFormat("sabund");  }
+               if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile);   }
                else {  inputFileNames.push_back(sabundfile);  }                
                
                for (int p = 0; p < inputFileNames.size(); p++) {
@@ -200,24 +258,30 @@ int CatchAllCommand::execute() {
                                m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
                        }
                        
-                       InputData* input = new InputData(inputFileNames[p], "sabund");
-                       SAbundVector* sabund = input->getSAbundVector();
+                       InputData input(inputFileNames[p], "sabund");
+                       SAbundVector* sabund = input.getSAbundVector();
                        string lastLabel = sabund->getLabel();
                                                        
                        set<string> processedLabels;
                        set<string> userLabels = labels;
                        
-                       string summaryfilename = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "catchall.summary";
+            map<string, string> variables;
+            variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p]));
+                       string summaryfilename = getOutputFileName("summary", variables);
                        summaryfilename = m->getFullPathName(summaryfilename);
                        
+            if (m->debug) { m->mothurOut("[DEBUG]: Input File = " + inputFileNames[p] + ".\n[DEBUG]: inputdata address = " + toString(&input) + ".\n[DEBUG]: sabund address = " + toString(&sabund) + ".\n"); } 
+            
                        ofstream out;
                        m->openOutputFile(summaryfilename, out);        
                        
                        out << "label\tmodel\testimate\tlci\tuci" << endl;
+            
+            if (m->debug) { string open = "no"; if (out.is_open()) { open = "yes"; } m->mothurOut("[DEBUG]: output stream is open = " + open + ".\n"); }
                        
                        //for each label the user selected
                        while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
-
+                               
                                                
                                if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
                                                m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
@@ -225,32 +289,52 @@ int CatchAllCommand::execute() {
                                                //create catchall input file from mothur's inputfile
                                                string filename = process(sabund, inputFileNames[p]);
                                                string outputPath = m->getPathName(filename);
-                                       
+                                                                                       
                                                //create system command
                                                string catchAllCommand = "";
-                                               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                                                       catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
+                                               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+                                                       catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + + "\" 1";
                                                #else
-                                                       if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); }
-                                                       catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + "\" 1";
-                                                       //wrap entire string in ""
-                                                       catchAllCommand = "\"" + catchAllCommand + "\"";
+                            //removes extra '\\' catchall doesnt like that
+                            vector<string> tempNames;
+                            string tempFilename = filename;
+                            m->splitAtDash(tempFilename, tempNames);
+                            tempFilename = tempNames[0];
+                            tempNames.clear();
+                            string tempOutputPath = outputPath;
+                            m->splitAtDash(tempOutputPath, tempNames);
+                            tempOutputPath = tempNames[0];
+                            if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
+                            catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \""  + tempOutputPath + "\" 1";
+                            catchAllCommand = "\"" + catchAllCommand + "\"";
                                                #endif
-                                                                               //run catchall
+                        
+                        if (m->debug) {  m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
+                    
+                                               //run catchall
                                                system(catchAllCommand.c_str());
-                                       
-                                               remove(filename.c_str());
+                    
+                        if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
+                    
+                        if (!m->debug) { m->mothurRemove(filename); }
+
                                        
                                                filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
+                                               if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
                                        
-                                               outputNames.push_back(filename + "_Analysis.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv");
-                                               outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv");
-                                               outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv");
-                                               outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv");
-                                       
+                        variables["[filename]"] = filename;
+                                               outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
+                                               outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
+                        outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
+                        outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
+                        
+                        if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
+                    
                                                createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
+                    
+                        if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
                                                                                        
-                                               if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str());    }  delete input;  delete sabund;  return 0; }
+                                               if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);   }  delete sabund;  return 0; }
 
                                                processedLabels.insert(sabund->getLabel());
                                                userLabels.erase(sabund->getLabel());
@@ -260,7 +344,7 @@ int CatchAllCommand::execute() {
                                                string saveLabel = sabund->getLabel();
                                                
                                                delete sabund;          
-                                               sabund = (input->getSAbundVector(lastLabel));
+                                               sabund = (input.getSAbundVector(lastLabel));
                                                
                                                m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
                                                
@@ -268,32 +352,53 @@ int CatchAllCommand::execute() {
                                                //create catchall input file from mothur's inputfile
                                                string filename = process(sabund, inputFileNames[p]);
                                                string outputPath = m->getPathName(filename);
-                                               
+                                                                                       
                                                //create system command
                                                string catchAllCommand = "";
-                                               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                                                       catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
+                                               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+                            catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + + "\" 1";
                                                #else
-                                                       if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); }
-                                                       catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + "\" 1";
+                            //removes extra '\\' catchall doesnt like that
+                            vector<string> tempNames;
+                            string tempFilename = filename;
+                            m->splitAtDash(tempFilename, tempNames);
+                            tempFilename = tempNames[0];
+                            tempNames.clear();
+                            string tempOutputPath = outputPath;
+                            m->splitAtDash(tempOutputPath, tempNames);
+                            tempOutputPath = tempNames[0];
+                                                       if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
+                                                       catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \""  + tempOutputPath + "\" 1";
                                                        catchAllCommand = "\"" + catchAllCommand + "\"";
                                                #endif
-
+                        
+                        if (m->debug) {  m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
+                    
                                                //run catchall
                                                system(catchAllCommand.c_str());
-                                       
-                                               remove(filename.c_str());
+                    
+                        if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
+                    
+                        if (!m->debug) { m->mothurRemove(filename); }
+
                                        
                                                filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
+                                               if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
                                        
-                                               outputNames.push_back(filename + "_Analysis.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv");
-                                               outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv");
-                                               outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv");
-                                               outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv");
-                                       
+                        variables["[filename]"] = filename;
+                        outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
+                        outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
+                        outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
+                        outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
+                        
+                    
+                        if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
+                    
                                                createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
+                    
+                        if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
                                        
-                                               if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str());    }  delete input;  delete sabund;  return 0; }
+                                               if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);   }   delete sabund;  return 0; }
 
                                                processedLabels.insert(sabund->getLabel());
                                                userLabels.erase(sabund->getLabel());
@@ -306,7 +411,7 @@ int CatchAllCommand::execute() {
                                lastLabel = sabund->getLabel(); 
                                
                                delete sabund;          
-                               sabund = (input->getSAbundVector());
+                               sabund = (input.getSAbundVector());
                        }
                        
                        //output error messages about any remaining user labels
@@ -325,7 +430,7 @@ int CatchAllCommand::execute() {
                        //run last label if you need to
                        if (needToRun == true)  {
                                if (sabund != NULL) {   delete sabund;  }
-                               sabund = (input->getSAbundVector(lastLabel));
+                               sabund = (input.getSAbundVector(lastLabel));
                                
                                m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
                                
@@ -335,40 +440,57 @@ int CatchAllCommand::execute() {
                                
                                //create system command
                                string catchAllCommand = "";
-                               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                                       catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
+                               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+                    catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + + "\" 1";
                                #else
-                                       if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); }
-                                       catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + "\" 1";
-                                       catchAllCommand = "\"" + catchAllCommand + "\"";
+                    //removes extra '\\' catchall doesnt like that
+                    vector<string> tempNames;
+                    string tempFilename = filename;
+                    m->splitAtDash(tempFilename, tempNames);
+                    tempFilename = tempNames[0];
+                    tempNames.clear();
+                    string tempOutputPath = outputPath;
+                    m->splitAtDash(tempOutputPath, tempNames);
+                    tempOutputPath = tempNames[0];
+                    if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
+                    catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \""  + tempOutputPath + "\" 1";
+                    catchAllCommand = "\"" + catchAllCommand + "\"";
                                #endif
+                
+                if (m->debug) {  m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
                                
                                //run catchall
                                system(catchAllCommand.c_str());
+                
+                if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
                                
-                               remove(filename.c_str());
+                               if (!m->debug) { m->mothurRemove(filename); }
                                
                                filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
+                               if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
                                
-                               outputNames.push_back(filename + "_Analysis.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv");
-                               outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv");
-                               outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv");
-                               outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv");        
-                               
+                               variables["[filename]"] = filename;
+                outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
+                outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
+                outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
+                outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
+                if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
+                
                                createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
+                
+                if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
                                
                                delete sabund;
                        }
                        
                        out.close();
-                       delete input; 
                        
-                       if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str()); } return 0; }
+                       if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);        } return 0; }
                                
                }
                
                if (sharedfile == "") {  
-                       string summaryfilename = outputDir + m->getRootName(m->getSimpleName(inputFileNames[0])) + "catchall.summary";
+                       string summaryfilename = savedOutputDir + m->getRootName(m->getSimpleName(inputFileNames[0])) + "catchall.summary";
                        summaryfilename = m->getFullPathName(summaryfilename);
                        outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
                }else { //combine summaries
@@ -396,20 +518,28 @@ int CatchAllCommand::execute() {
 //**********************************************************************************************************************
 string CatchAllCommand::process(SAbundVector* sabund, string file1) {
        try {
-               string filename = outputDir + m->getRootName(m->getSimpleName(file1)) + sabund->getLabel() + ".csv";
+        map<string, string> variables;
+        variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(file1));
+        variables["[distance]"] = sabund->getLabel();
+        string filename = getOutputFileName("sabund", variables);
                filename = m->getFullPathName(filename);
        
                ofstream out;
                m->openOutputFile(filename, out);
                
+        if (m->debug) { m->mothurOut("[DEBUG]: Creating " + filename + " file for catchall, shown below.\n\n"); }
+        
                for (int i = 1; i <= sabund->getMaxRank(); i++) {
                        int temp = sabund->get(i);
                        
                        if (temp != 0) {
                                out << i << "," << temp << endl;
+                if (m->debug) { m->mothurOut(toString(i) + "," + toString(temp) + "\n"); }
                        }
                }
                out.close();
+        
+        if (m->debug) { m->mothurOut("[DEBUG]: Done creating " + filename + " file for catchall, shown above.\n\n"); }
                
                return filename;
        
@@ -424,7 +554,9 @@ string CatchAllCommand::combineSummmary(vector<string>& outputNames) {
        try {
                
                ofstream out;
-               string combineFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "catchall.summary";
+        map<string, string> variables;
+        variables["[filename]"] = savedOutputDir + m->getRootName(m->getSimpleName(sharedfile));
+        string combineFileName = getOutputFileName("summary", variables);
                
                //open combined file
                m->openOutputFile(combineFileName, out);
@@ -471,7 +603,7 @@ string CatchAllCommand::combineSummmary(vector<string>& outputNames) {
                        numLines = thisFilesLines.size();
                        
                        temp.close();
-                       remove(outputNames[i].c_str());
+                       m->mothurRemove(outputNames[i]);
                }
                
                //for each label
@@ -500,8 +632,10 @@ int CatchAllCommand::createSummaryFile(string file1, string label, ofstream& out
        try {
                
                ifstream in;
-               m->openInputFile(file1, in);
+               int able = m->openInputFile(file1, in, "noerror");
                
+               if (able == 1) {  m->mothurOut("[ERROR]: the catchall program did not run properly. Please check to make sure it is located in the same folder as your mothur executable.");m->mothurOutEndLine();  m->control_pressed = true; return 0; }
+                       
                if (!in.eof()) {
                        
                        string header = m->getline(in); m->gobble(in);
@@ -570,14 +704,14 @@ vector<string> CatchAllCommand::parseSharedFile(string filename) {
                vector<string> filenames;
                
                //read first line
-               InputData* input = new InputData(filename, "sharedfile");
-               vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
+               InputData input(filename, "sharedfile");
+               vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
                
                string sharedFileRoot = outputDir + m->getRootName(m->getSimpleName(filename));
                
                //clears file before we start to write to it below
                for (int i=0; i<lookup.size(); i++) {
-                       remove((sharedFileRoot + lookup[i]->getGroup() + ".sabund").c_str());
+                       m->mothurRemove((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
                        filenames.push_back((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
                        groups.push_back(lookup[i]->getGroup());
                }
@@ -593,11 +727,9 @@ vector<string> CatchAllCommand::parseSharedFile(string filename) {
                        }
                        
                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
-                       lookup = input->getSharedRAbundVectors();
+                       lookup = input.getSharedRAbundVectors();
                }
                
-               delete input;
-               
                return filenames;
        }
        catch(exception& e) {