5 * Created by westcott on 5/11/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "catchallcommand.h"
12 //**********************************************************************************************************************
13 vector<string> CatchAllCommand::setParameters(){
15 CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
16 //can choose shared or sabund not both, so put them in the same chooseOnlyOneGroup
17 CommandParameter pshared("shared", "InputTypes", "", "", "catchallInputs", "catchallInputs", "none","analysis-bestanalysis-models-bubble-summary",false,false,true); parameters.push_back(pshared);
18 CommandParameter psabund("sabund", "InputTypes", "", "", "catchallInputs", "catchallInputs", "none","analysis-bestanalysis-models-bubble-summary",false,false,true); parameters.push_back(psabund);
19 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
20 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
22 vector<string> myArray;
23 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
27 m->errorOut(e, "CatchAllCommand", "setParameters");
31 //**********************************************************************************************************************
32 string CatchAllCommand::getHelpString(){
34 string helpString = "";
35 helpString += "The catchall command interfaces mothur with the catchall program written by Linda Woodard, Sean Connolly and John Bunge.\n";
36 helpString += "For more information about catchall refer to http://www.northeastern.edu/catchall/index.html \n";
37 helpString += "The catchall executable must be in the same folder as your mothur executable. \n";
38 helpString += "If you are a MAC or Linux user you must also have installed mono, a link to mono is on the webpage. \n";
39 helpString += "The catchall command parameters are shared, sabund and label. shared or sabund is required. \n";
40 helpString += "The label parameter is used to analyze specific labels in your input.\n";
41 helpString += "The catchall command should be in the following format: \n";
42 helpString += "catchall(sabund=yourSabundFile) \n";
43 helpString += "Example: catchall(sabund=abrecovery.fn.sabund) \n";
47 m->errorOut(e, "CatchAllCommand", "getHelpString");
51 //**********************************************************************************************************************
52 string CatchAllCommand::getOutputPattern(string type) {
56 if (type == "analysis") { pattern = "[filename],_Analysis.csv"; }
57 else if (type == "bestanalysis") { pattern = "[filename],_BestModelsAnalysis.csv"; }
58 else if (type == "models") { pattern = "[filename],_BestModelsAnalysis.csv"; }
59 else if (type == "bubble") { pattern = "[filename],_BubblePlot.csv"; }
60 else if (type == "summary") { pattern = "[filename],catchall.summary"; }
61 else if (type == "sabund") { pattern = "[filename],[distance],csv"; }
62 else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
67 m->errorOut(e, "CatchAllCommand", "getOutputPattern");
71 //**********************************************************************************************************************
72 CatchAllCommand::CatchAllCommand(){
74 abort = true; calledHelp = true;
76 //initialize outputTypes
77 vector<string> tempOutNames;
78 outputTypes["analysis"] = tempOutNames;
79 outputTypes["bestanalysis"] = tempOutNames;
80 outputTypes["models"] = tempOutNames;
81 outputTypes["bubble"] = tempOutNames;
82 outputTypes["summary"] = tempOutNames;
83 outputTypes["sabund"] = tempOutNames;
86 m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
90 /**************************************************************************************/
91 CatchAllCommand::CatchAllCommand(string option) {
94 abort = false; calledHelp = false;
97 //allow user to run help
98 if(option == "help") { help(); abort = true; calledHelp = true; }
99 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
102 vector<string> myArray = setParameters();
104 OptionParser parser(option);
105 map<string,string> parameters = parser.getParameters();
107 ValidParameters validParameter;
108 map<string, string>::iterator it;
110 //check to make sure all parameters are valid for command
111 for (it = parameters.begin(); it != parameters.end(); it++) {
112 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
115 //initialize outputTypes
116 vector<string> tempOutNames;
117 outputTypes["analysis"] = tempOutNames;
118 outputTypes["bestanalysis"] = tempOutNames;
119 outputTypes["models"] = tempOutNames;
120 outputTypes["bubble"] = tempOutNames;
121 outputTypes["summary"] = tempOutNames;
122 outputTypes["sabund"] = tempOutNames;
125 //if the user changes the input directory command factory will send this info to us in the output parameter
126 string inputDir = validParameter.validFile(parameters, "inputdir", false);
127 if (inputDir == "not found"){ inputDir = ""; }
130 it = parameters.find("sabund");
131 //user has given a template file
132 if(it != parameters.end()){
133 path = m->hasPath(it->second);
134 //if the user has not given a path then, add inputdir. else leave path alone.
135 if (path == "") { parameters["sabund"] = inputDir + it->second; }
138 it = parameters.find("shared");
139 //user has given a template file
140 if(it != parameters.end()){
141 path = m->hasPath(it->second);
142 //if the user has not given a path then, add inputdir. else leave path alone.
143 if (path == "") { parameters["shared"] = inputDir + it->second; }
147 //check for required parameters
148 sabundfile = validParameter.validFile(parameters, "sabund", true);
149 if (sabundfile == "not open") { sabundfile = ""; abort = true; }
150 else if (sabundfile == "not found") { sabundfile = ""; }
151 else { m->setSabundFile(sabundfile); }
153 sharedfile = validParameter.validFile(parameters, "shared", true);
154 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
155 else if (sharedfile == "not found") { sharedfile = ""; }
156 else { m->setSharedFile(sharedfile); }
158 string label = validParameter.validFile(parameters, "label", false);
159 if (label == "not found") { label = ""; }
161 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
162 else { allLines = 1; }
165 if ((sharedfile == "") && (sabundfile == "")) {
166 //is there are current file available for either of these?
167 //give priority to shared, then sabund
168 //if there is a current shared file, use it
169 sharedfile = m->getSharedFile();
170 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
172 sabundfile = m->getSabundFile();
173 if (sabundfile != "") { m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); }
175 m->mothurOut("No valid current files. You must provide a sabund or shared file before you can use the catchall command."); m->mothurOutEndLine();
181 //if the user changes the output directory command factory will send this info to us in the output parameter
182 outputDir = validParameter.validFile(parameters, "outputdir", false);
183 if (outputDir == "not found"){
184 if (sabundfile != "") { outputDir = m->hasPath(sabundfile); }
185 else { outputDir = m->hasPath(sharedfile); }
190 catch(exception& e) {
191 m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
195 /**************************************************************************************/
196 int CatchAllCommand::execute() {
199 if (abort == true) { if (calledHelp) { return 0; } return 2; }
201 //get location of catchall
203 path = path.substr(0, (path.find_last_of("othur")-5));
204 path = m->getFullPathName(path);
206 if (m->debug) { m->mothurOut("[DEBUG]: mothur's path = " + path + "\n"); }
208 savedOutputDir = outputDir;
209 string catchAllCommandExe = "";
210 string catchAllTest = "";
211 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
212 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.
213 catchAllTest = path + "CatchAllcmdL.exe";
215 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.
216 catchAllTest = path + "CatchAllcmdW.exe";
219 //test to make sure formatdb exists
221 catchAllTest = m->getFullPathName(catchAllTest);
222 int ableToOpen = m->openInputFile(catchAllTest, in, "no error"); in.close();
223 if(ableToOpen == 1) {
224 m->mothurOut(catchAllTest + " file does not exist. Checking path... \n");
225 //check to see if uchime is in the path??
227 string programName = "CatchAllcmdW.exe";
228 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
229 programName = "CatchAllcmdL.exe";
231 string cLocation = m->findProgramPath(programName);
234 ableToOpen = m->openInputFile(cLocation, in2, "no error"); in2.close();
236 if(ableToOpen == 1) { m->mothurOut("[ERROR]: " + cLocation + " file does not exist. mothur requires the catchall executable."); m->mothurOutEndLine(); return 0; }
237 else { m->mothurOut("Found catchall in your path, using " + cLocation + "\n"); catchAllTest = cLocation; }
239 catchAllTest = m->getFullPathName(catchAllTest);
241 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
242 catchAllCommandExe += "mono \"" + catchAllTest + "\" ";
244 catchAllCommandExe += "\"" + catchAllTest + "\" ";
247 //prepare full output directory
248 outputDir = m->getFullPathName(outputDir);
250 if (m->debug) { m->mothurOut("[DEBUG]: catchall location = " + catchAllCommandExe + "\n[DEBUG]: outputDir = " + outputDir + "\n"); }
252 vector<string> inputFileNames;
253 if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile); }
254 else { inputFileNames.push_back(sabundfile); }
256 for (int p = 0; p < inputFileNames.size(); p++) {
257 if (inputFileNames.size() > 1) {
258 m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
261 InputData input(inputFileNames[p], "sabund");
262 SAbundVector* sabund = input.getSAbundVector();
263 string lastLabel = sabund->getLabel();
265 set<string> processedLabels;
266 set<string> userLabels = labels;
268 map<string, string> variables;
269 variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p]));
270 string summaryfilename = getOutputFileName("summary", variables);
271 summaryfilename = m->getFullPathName(summaryfilename);
273 if (m->debug) { m->mothurOut("[DEBUG]: Input File = " + inputFileNames[p] + ".\n[DEBUG]: inputdata address = " + toString(&input) + ".\n[DEBUG]: sabund address = " + toString(&sabund) + ".\n"); }
276 m->openOutputFile(summaryfilename, out);
278 out << "label\tmodel\testimate\tlci\tuci" << endl;
280 if (m->debug) { string open = "no"; if (out.is_open()) { open = "yes"; } m->mothurOut("[DEBUG]: output stream is open = " + open + ".\n"); }
282 //for each label the user selected
283 while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
286 if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
287 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
289 //create catchall input file from mothur's inputfile
290 string filename = process(sabund, inputFileNames[p]);
291 string outputPath = m->getPathName(filename);
293 //create system command
294 string catchAllCommand = "";
295 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
296 catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \"" + outputPath + + "\" 1";
298 //removes extra '\\' catchall doesnt like that
299 vector<string> tempNames;
300 string tempFilename = filename;
301 m->splitAtDash(tempFilename, tempNames);
302 tempFilename = tempNames[0];
304 string tempOutputPath = outputPath;
305 m->splitAtDash(tempOutputPath, tempNames);
306 tempOutputPath = tempNames[0];
307 if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
308 catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \"" + tempOutputPath + "\" 1";
309 catchAllCommand = "\"" + catchAllCommand + "\"";
312 if (m->debug) { m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
315 system(catchAllCommand.c_str());
317 if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
319 if (!m->debug) { m->mothurRemove(filename); }
322 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
323 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
325 variables["[filename]"] = filename;
326 outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
327 outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
328 outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
329 outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
331 if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
333 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
335 if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
337 if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]); } delete sabund; return 0; }
339 processedLabels.insert(sabund->getLabel());
340 userLabels.erase(sabund->getLabel());
343 if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
344 string saveLabel = sabund->getLabel();
347 sabund = (input.getSAbundVector(lastLabel));
349 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
352 //create catchall input file from mothur's inputfile
353 string filename = process(sabund, inputFileNames[p]);
354 string outputPath = m->getPathName(filename);
356 //create system command
357 string catchAllCommand = "";
358 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
359 catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \"" + outputPath + + "\" 1";
361 //removes extra '\\' catchall doesnt like that
362 vector<string> tempNames;
363 string tempFilename = filename;
364 m->splitAtDash(tempFilename, tempNames);
365 tempFilename = tempNames[0];
367 string tempOutputPath = outputPath;
368 m->splitAtDash(tempOutputPath, tempNames);
369 tempOutputPath = tempNames[0];
370 if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
371 catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \"" + tempOutputPath + "\" 1";
372 catchAllCommand = "\"" + catchAllCommand + "\"";
375 if (m->debug) { m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
378 system(catchAllCommand.c_str());
380 if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
382 if (!m->debug) { m->mothurRemove(filename); }
385 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
386 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
388 variables["[filename]"] = filename;
389 outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
390 outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
391 outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
392 outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
395 if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
397 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
399 if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
401 if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]); } delete sabund; return 0; }
403 processedLabels.insert(sabund->getLabel());
404 userLabels.erase(sabund->getLabel());
406 //restore real lastlabel to save below
407 sabund->setLabel(saveLabel);
411 lastLabel = sabund->getLabel();
414 sabund = (input.getSAbundVector());
417 //output error messages about any remaining user labels
418 set<string>::iterator it;
419 bool needToRun = false;
420 for (it = userLabels.begin(); it != userLabels.end(); it++) {
421 m->mothurOut("Your file does not include the label " + *it);
422 if (processedLabels.count(lastLabel) != 1) {
423 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
426 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
430 //run last label if you need to
431 if (needToRun == true) {
432 if (sabund != NULL) { delete sabund; }
433 sabund = (input.getSAbundVector(lastLabel));
435 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
437 //create catchall input file from mothur's inputfile
438 string filename = process(sabund, inputFileNames[p]);
439 string outputPath = m->getPathName(filename);
441 //create system command
442 string catchAllCommand = "";
443 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
444 catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \"" + outputPath + + "\" 1";
446 //removes extra '\\' catchall doesnt like that
447 vector<string> tempNames;
448 string tempFilename = filename;
449 m->splitAtDash(tempFilename, tempNames);
450 tempFilename = tempNames[0];
452 string tempOutputPath = outputPath;
453 m->splitAtDash(tempOutputPath, tempNames);
454 tempOutputPath = tempNames[0];
455 if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
456 catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \"" + tempOutputPath + "\" 1";
457 catchAllCommand = "\"" + catchAllCommand + "\"";
460 if (m->debug) { m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
463 system(catchAllCommand.c_str());
465 if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
467 if (!m->debug) { m->mothurRemove(filename); }
469 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
470 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
472 variables["[filename]"] = filename;
473 outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
474 outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
475 outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
476 outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
477 if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
479 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
481 if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
488 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]); } return 0; }
492 if (sharedfile == "") {
493 string summaryfilename = savedOutputDir + m->getRootName(m->getSimpleName(inputFileNames[0])) + "catchall.summary";
494 summaryfilename = m->getFullPathName(summaryfilename);
495 outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
496 }else { //combine summaries
497 vector<string> sumNames;
498 for (int i = 0; i < inputFileNames.size(); i++) {
499 sumNames.push_back(m->getFullPathName(outputDir + m->getRootName(m->getSimpleName(inputFileNames[i])) + "catchall.summary"));
501 string summaryfilename = combineSummmary(sumNames);
502 outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
505 m->mothurOutEndLine();
506 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
507 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
508 m->mothurOutEndLine();
513 catch(exception& e) {
514 m->errorOut(e, "CatchAllCommand", "execute");
518 //**********************************************************************************************************************
519 string CatchAllCommand::process(SAbundVector* sabund, string file1) {
521 map<string, string> variables;
522 variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(file1));
523 variables["[distance]"] = sabund->getLabel();
524 string filename = getOutputFileName("sabund", variables);
525 filename = m->getFullPathName(filename);
528 m->openOutputFile(filename, out);
530 if (m->debug) { m->mothurOut("[DEBUG]: Creating " + filename + " file for catchall, shown below.\n\n"); }
532 for (int i = 1; i <= sabund->getMaxRank(); i++) {
533 int temp = sabund->get(i);
536 out << i << "," << temp << endl;
537 if (m->debug) { m->mothurOut(toString(i) + "," + toString(temp) + "\n"); }
542 if (m->debug) { m->mothurOut("[DEBUG]: Done creating " + filename + " file for catchall, shown above.\n\n"); }
547 catch(exception& e) {
548 m->errorOut(e, "CatchAllCommand", "process");
552 //*********************************************************************************************************************
553 string CatchAllCommand::combineSummmary(vector<string>& outputNames) {
557 map<string, string> variables;
558 variables["[filename]"] = savedOutputDir + m->getRootName(m->getSimpleName(sharedfile));
559 string combineFileName = getOutputFileName("summary", variables);
562 m->openOutputFile(combineFileName, out);
564 out << "label\tgroup\tmodel\testimate\tlci\tuci" << endl;
566 //open each groups summary file
567 string newLabel = "";
569 map<string, vector<string> > files;
570 for (int i=0; i<outputNames.size(); i++) {
571 vector<string> thisFilesLines;
574 m->openInputFile(outputNames[i], temp);
576 //read through first line - labels
581 while (!temp.eof()) {
583 string thisLine = "";
586 for (int j = 0; j < 5; j++) {
590 if (j == 1) { thisLine += groups[i] + "\t" + tempLabel + "\t"; }
591 else{ thisLine += tempLabel + "\t"; }
596 thisFilesLines.push_back(thisLine);
601 files[outputNames[i]] = thisFilesLines;
603 numLines = thisFilesLines.size();
606 m->mothurRemove(outputNames[i]);
610 for (int k = 0; k < numLines; k++) {
612 //grab summary data for each group
613 for (int i=0; i<outputNames.size(); i++) {
614 out << files[outputNames[i]][k];
621 //return combine file name
622 return combineFileName;
625 catch(exception& e) {
626 m->errorOut(e, "CatchAllCommand", "combineSummmary");
630 //**********************************************************************************************************************
631 int CatchAllCommand::createSummaryFile(string file1, string label, ofstream& out) {
635 int able = m->openInputFile(file1, in, "noerror");
637 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; }
641 string header = m->getline(in); m->gobble(in);
643 int pos = header.find("Total Number of Observed Species =");
644 string numString = "";
647 if (pos == string::npos) { m->mothurOut("[ERROR]: cannot parse " + file1); m->mothurOutEndLine(); }
649 //pos will be the position of the T in total, so we want to count to the position of =
660 if (pos > header.length()) { m->mothurOut("Cannot find number of OTUs in " + file1); m->mothurOutEndLine(); in.close(); return 0; }
664 string firstline = m->getline(in); m->gobble(in);
665 vector<string> values;
666 m->splitAtComma(firstline, values);
668 values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
670 if (values.size() == 1) { //grab next line if firstline didn't have what you wanted
671 string secondline = m->getline(in); m->gobble(in);
673 m->splitAtComma(secondline, values);
675 values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
678 if (values.size() == 1) { //still not what we wanted fill values with numOTUs
679 values.resize(8, "");
681 values[4] = numString;
682 values[6] = numString;
683 values[7] = numString;
686 if (values.size() < 8) { values.resize(8, ""); }
688 out << label << '\t' << values[1] << '\t' << values[4] << '\t' << values[6] << '\t' << values[7] << endl;
696 catch(exception& e) {
697 m->errorOut(e, "CatchAllCommand", "createSummaryFile");
701 //**********************************************************************************************************************
702 vector<string> CatchAllCommand::parseSharedFile(string filename) {
704 vector<string> filenames;
707 InputData input(filename, "sharedfile");
708 vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
710 string sharedFileRoot = outputDir + m->getRootName(m->getSimpleName(filename));
712 //clears file before we start to write to it below
713 for (int i=0; i<lookup.size(); i++) {
714 m->mothurRemove((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
715 filenames.push_back((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
716 groups.push_back(lookup[i]->getGroup());
719 while(lookup[0] != NULL) {
721 for (int i = 0; i < lookup.size(); i++) {
722 SAbundVector sav = lookup[i]->getSAbundVector();
724 m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".sabund", out);
729 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
730 lookup = input.getSharedRAbundVectors();
735 catch(exception& e) {
736 m->errorOut(e, "CatchAllCommand", "parseSharedFile");
740 /**************************************************************************************/