]> git.donarmstrong.com Git - mothur.git/blobdiff - catchallcommand.cpp
get.oturep change and trim.seqs fix
[mothur.git] / catchallcommand.cpp
index 8f2841358dd4bbb91b69c2a530b6332b8fc2d131..43fd9538e40cbe7e62adb8468b3408af715a0fb9 100644 (file)
@@ -28,6 +28,7 @@ CatchAllCommand::CatchAllCommand(){
                //initialize outputTypes
                vector<string> tempOutNames;
                outputTypes["csv"] = tempOutNames;
+               outputTypes["summary"] = tempOutNames;
        }
        catch(exception& e) {
                m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
@@ -86,6 +87,7 @@ CatchAllCommand::CatchAllCommand(string option)  {
                        //initialize outputTypes
                        vector<string> tempOutNames;
                        outputTypes["csv"] = tempOutNames;
+                       outputTypes["summary"] = 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);              
@@ -131,7 +133,7 @@ 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 a folder called catchall in the same folder as your mothur executable, similar to mothur's requirements for using blast. \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 sabund and label, sabund is required. \n");
                m->mothurOut("The label parameter is used to analyze specific labels in your input.\n");
@@ -162,9 +164,9 @@ int CatchAllCommand::execute() {
 
                string catchAllCommandExe = ""; 
                #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                       catchAllCommandExe += "mono " + path + "catchall/CatchAllcmdL.exe ";
+                       catchAllCommandExe += "mono " + path + "CatchAllcmdL.exe ";
                #else
-                       catchAllCommandExe += path + "catchall/CatchAllcmdW.exe ";
+                       catchAllCommandExe += "\"" + path + "CatchAllcmdW.exe\"" + " ";
                #endif
                
                read = new ReadOTUFile(sabundfile);     
@@ -177,6 +179,15 @@ int CatchAllCommand::execute() {
                set<string> processedLabels;
                set<string> userLabels = labels;
                
+               string summaryfilename = outputDir + m->getRootName(m->getSimpleName(sabundfile)) + "catchall.summary";
+               summaryfilename = m->getFullPathName(summaryfilename);
+               outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
+               
+               ofstream out;
+               m->openOutputFile(summaryfilename, out);        
+               
+               out << "label\tmodel\testimate\tlci\tuci" << endl;
+               
                //for each label the user selected
                while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
 
@@ -189,9 +200,16 @@ int CatchAllCommand::execute() {
                                        string outputPath = m->getPathName(filename);
                                
                                        //create system command
-                                       string catchAllCommand = catchAllCommandExe + filename + " " + outputPath + " 1";
-                               
-                                       //run catchall
+                                       string catchAllCommand = "";
+                                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                                               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 + "\"";
+                                       #endif
+                                                                       //run catchall
                                        system(catchAllCommand.c_str());
                                
                                        remove(filename.c_str());
@@ -203,8 +221,9 @@ int CatchAllCommand::execute() {
                                        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");
                                
+                                       createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
                                                                                
-                                       if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str()); } delete read;  delete input; globaldata->ginput = NULL; delete sabund;  return 0; }
+                                       if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str());    } delete read;  delete input; globaldata->ginput = NULL; delete sabund;  return 0; }
 
                                        processedLabels.insert(sabund->getLabel());
                                        userLabels.erase(sabund->getLabel());
@@ -224,7 +243,14 @@ int CatchAllCommand::execute() {
                                        string outputPath = m->getPathName(filename);
                                        
                                        //create system command
-                                       string catchAllCommand = catchAllCommandExe + filename + " " + outputPath + " 1";
+                                       string catchAllCommand = "";
+                                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                                               catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
+                                       #else
+                                               if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); }
+                                               catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + "\" 1";
+                                               catchAllCommand = "\"" + catchAllCommand + "\"";
+                                       #endif
 
                                        //run catchall
                                        system(catchAllCommand.c_str());
@@ -238,7 +264,9 @@ int CatchAllCommand::execute() {
                                        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");
                                
-                                       if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str()); } delete read;  delete input; globaldata->ginput = NULL; delete sabund;  return 0; }
+                                       createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
+                               
+                                       if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {remove(outputNames[i].c_str());    } delete read;  delete input; globaldata->ginput = NULL; delete sabund;  return 0; }
 
                                        processedLabels.insert(sabund->getLabel());
                                        userLabels.erase(sabund->getLabel());
@@ -279,7 +307,14 @@ int CatchAllCommand::execute() {
                        string outputPath = m->getPathName(filename);
                        
                        //create system command
-                       string catchAllCommand = catchAllCommandExe + filename + " " + outputPath + " 1";
+                       string catchAllCommand = "";
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
+                       #else
+                               if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); }
+                               catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + "\" 1";
+                               catchAllCommand = "\"" + catchAllCommand + "\"";
+                       #endif
                        
                        //run catchall
                        system(catchAllCommand.c_str());
@@ -291,11 +326,14 @@ int CatchAllCommand::execute() {
                        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");                        
+                       outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv");        
+                       
+                       createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
                        
                        delete sabund;
                }
-
+               
+               out.close();
                delete read;
                delete input; globaldata->ginput = NULL;
                
@@ -340,7 +378,73 @@ string CatchAllCommand::process(SAbundVector* sabund) {
                exit(1);
        }
 }
+//**********************************************************************************************************************
+int CatchAllCommand::createSummaryFile(string file1, string label, ofstream& out) {
+       try {
+               
+               ifstream in;
+               m->openInputFile(file1, in);
+               
+               if (!in.eof()) {
+                       
+                       string header = m->getline(in); m->gobble(in);
+                       
+                       int pos = header.find("Total Number of Observed Species =");
+                       string numString = "";
+                       
+                       
+                       if (pos == string::npos) { m->mothurOut("[ERROR]: cannot parse " + file1); m->mothurOutEndLine(); }
+                       else {
+                               //pos will be the position of the T in total, so we want to count to the position of =
+                               pos += 34;
+                               char c=header[pos];
+                               while (c != ','){
+                                       if (c != ' ') {
+                                               numString += c;
+                                       }
+                                       pos++;
+                                       c=header[pos];
+                                       
+                                       //sanity check
+                                       if (pos > header.length()) { m->mothurOut("Cannot find number of OTUs in " + file1); m->mothurOutEndLine(); in.close(); return 0; }
+                               }
+                       }
+                                                                                                                         
+                       string firstline = m->getline(in); m->gobble(in);
+                       vector<string> values;
+                       m->splitAtComma(firstline, values);
+                       
+                       values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
+                       
+                       if (values.size() == 1) { //grab next line if firstline didn't have what you wanted
+                               string secondline = m->getline(in); m->gobble(in);
+                               values.clear();
+                               m->splitAtComma(secondline, values);
+                               
+                               values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
+                       }
+                       
+                       if (values.size() == 1) { //still not what we wanted fill values with numOTUs
+                               values.resize(8, "");
+                               values[1] = "Sobs";
+                               values[4] = numString;
+                               values[6] = numString;
+                               values[7] = numString;
+                       }
+                       
+                       if (values.size() < 8) { values.resize(8, ""); }
+                       
+                       out << label << '\t' << values[1] << '\t' << values[4] << '\t' << values[6] << '\t' << values[7] << endl;
+               }
+               
+               in.close();
+               
+               return 0;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "CatchAllCommand", "createSummaryFile");
+               exit(1);
+       }
+}
 /**************************************************************************************/
-
-
-