]> git.donarmstrong.com Git - mothur.git/blobdiff - catchallcommand.cpp
fixed catchall "clunky" names
[mothur.git] / catchallcommand.cpp
index b0e5eff6652a9defaa887eb7d21bb9bfe9e372a6..ace1b00dc0b45e9500d6ba9aa8657fc44b854042 100644 (file)
@@ -25,6 +25,7 @@ vector<string> CatchAllCommand::getValidParameters(){
 //**********************************************************************************************************************
 CatchAllCommand::CatchAllCommand(){    
        try {
+               abort = true; calledHelp = true;
                //initialize outputTypes
                vector<string> tempOutNames;
                outputTypes["csv"] = tempOutNames;
@@ -62,11 +63,11 @@ vector<string> CatchAllCommand::getRequiredFiles(){
 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 {
                        //valid paramters for this command
@@ -173,24 +174,27 @@ void CatchAllCommand::help(){
 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 = path.substr(0, (path.find_last_of("othur")-5));
                path = m->getFullPathName(path);
-
+               
+               savedOutputDir = outputDir;
                string catchAllCommandExe = ""; 
                #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
                        catchAllCommandExe += "mono " + path + "CatchAllcmdL.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.
                #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.
                #endif
                
+               //prepare full output directory
+               outputDir = m->getFullPathName(outputDir);
+               
                vector<string> inputFileNames;
                if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile);  globaldata->setFormat("sabund");  }
                else {  inputFileNames.push_back(sabundfile);  }                
@@ -236,12 +240,14 @@ int CatchAllCommand::execute() {
                                                        //wrap entire string in ""
                                                        catchAllCommand = "\"" + catchAllCommand + "\"";
                                                #endif
-                                                                               //run catchall
+                                       
+                                               //run catchall
                                                system(catchAllCommand.c_str());
                                        
                                                remove(filename.c_str());
                                        
                                                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");
@@ -285,6 +291,7 @@ int CatchAllCommand::execute() {
                                                remove(filename.c_str());
                                        
                                                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");
@@ -349,6 +356,7 @@ int CatchAllCommand::execute() {
                                remove(filename.c_str());
                                
                                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");
@@ -368,7 +376,7 @@ int CatchAllCommand::execute() {
                }
                
                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
@@ -378,6 +386,8 @@ int CatchAllCommand::execute() {
                        }
                        string summaryfilename = combineSummmary(sumNames);
                        outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
+                       
+                       globaldata->setSharedFile(sharedfile); globaldata->setFormat("sharedfile");
                }
                
                m->mothurOutEndLine();
@@ -424,7 +434,7 @@ string CatchAllCommand::combineSummmary(vector<string>& outputNames) {
        try {
                
                ofstream out;
-               string combineFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "catchall.summary";
+               string combineFileName = savedOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + "catchall.summary";
                
                //open combined file
                m->openOutputFile(combineFileName, out);