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;
85 m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
89 /**************************************************************************************/
90 CatchAllCommand::CatchAllCommand(string option) {
93 abort = false; calledHelp = false;
96 //allow user to run help
97 if(option == "help") { help(); abort = true; calledHelp = true; }
98 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
101 vector<string> myArray = setParameters();
103 OptionParser parser(option);
104 map<string,string> parameters = parser.getParameters();
106 ValidParameters validParameter;
107 map<string, string>::iterator it;
109 //check to make sure all parameters are valid for command
110 for (it = parameters.begin(); it != parameters.end(); it++) {
111 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
114 //initialize outputTypes
115 vector<string> tempOutNames;
116 outputTypes["analysis"] = tempOutNames;
117 outputTypes["bestanalysis"] = tempOutNames;
118 outputTypes["models"] = tempOutNames;
119 outputTypes["bubble"] = tempOutNames;
120 outputTypes["summary"] = tempOutNames;
123 //if the user changes the input directory command factory will send this info to us in the output parameter
124 string inputDir = validParameter.validFile(parameters, "inputdir", false);
125 if (inputDir == "not found"){ inputDir = ""; }
128 it = parameters.find("sabund");
129 //user has given a template file
130 if(it != parameters.end()){
131 path = m->hasPath(it->second);
132 //if the user has not given a path then, add inputdir. else leave path alone.
133 if (path == "") { parameters["sabund"] = inputDir + it->second; }
136 it = parameters.find("shared");
137 //user has given a template file
138 if(it != parameters.end()){
139 path = m->hasPath(it->second);
140 //if the user has not given a path then, add inputdir. else leave path alone.
141 if (path == "") { parameters["shared"] = inputDir + it->second; }
145 //check for required parameters
146 sabundfile = validParameter.validFile(parameters, "sabund", true);
147 if (sabundfile == "not open") { sabundfile = ""; abort = true; }
148 else if (sabundfile == "not found") { sabundfile = ""; }
149 else { m->setSabundFile(sabundfile); }
151 sharedfile = validParameter.validFile(parameters, "shared", true);
152 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
153 else if (sharedfile == "not found") { sharedfile = ""; }
154 else { m->setSharedFile(sharedfile); }
156 string label = validParameter.validFile(parameters, "label", false);
157 if (label == "not found") { label = ""; }
159 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
160 else { allLines = 1; }
163 if ((sharedfile == "") && (sabundfile == "")) {
164 //is there are current file available for either of these?
165 //give priority to shared, then sabund
166 //if there is a current shared file, use it
167 sharedfile = m->getSharedFile();
168 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
170 sabundfile = m->getSabundFile();
171 if (sabundfile != "") { m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); }
173 m->mothurOut("No valid current files. You must provide a sabund or shared file before you can use the catchall command."); m->mothurOutEndLine();
179 //if the user changes the output directory command factory will send this info to us in the output parameter
180 outputDir = validParameter.validFile(parameters, "outputdir", false);
181 if (outputDir == "not found"){
182 if (sabundfile != "") { outputDir = m->hasPath(sabundfile); }
183 else { outputDir = m->hasPath(sharedfile); }
188 catch(exception& e) {
189 m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
193 /**************************************************************************************/
194 int CatchAllCommand::execute() {
197 if (abort == true) { if (calledHelp) { return 0; } return 2; }
199 //get location of catchall
201 path = path.substr(0, (path.find_last_of("othur")-5));
202 path = m->getFullPathName(path);
204 if (m->debug) { m->mothurOut("[DEBUG]: mothur's path = " + path + "\n"); }
206 savedOutputDir = outputDir;
207 string catchAllCommandExe = "";
208 string catchAllTest = "";
209 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
210 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.
211 catchAllTest = path + "CatchAllcmdL.exe";
213 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.
214 catchAllTest = path + "CatchAllcmdW.exe";
217 //test to make sure formatdb exists
219 catchAllTest = m->getFullPathName(catchAllTest);
220 int ableToOpen = m->openInputFile(catchAllTest, in, "no error"); in.close();
221 if(ableToOpen == 1) {
222 m->mothurOut(catchAllTest + " file does not exist. Checking path... \n");
223 //check to see if uchime is in the path??
225 string programName = "CatchAllcmdW.exe";
226 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
227 programName = "CatchAllcmdL.exe";
229 string cLocation = m->findProgramPath(programName);
232 ableToOpen = m->openInputFile(cLocation, in2, "no error"); in2.close();
234 if(ableToOpen == 1) { m->mothurOut("[ERROR]: " + cLocation + " file does not exist. mothur requires the catchall executable."); m->mothurOutEndLine(); return 0; }
235 else { m->mothurOut("Found catchall in your path, using " + cLocation + "\n"); catchAllTest = cLocation; }
237 catchAllTest = m->getFullPathName(catchAllTest);
239 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
240 catchAllCommandExe += "mono " + catchAllTest + " ";
242 catchAllCommandExe += "\"" + catchAllTest + "\" ";
245 //prepare full output directory
246 outputDir = m->getFullPathName(outputDir);
248 if (m->debug) { m->mothurOut("[DEBUG]: catchall location = " + catchAllCommandExe + "\n[DEBUG]: outputDir = " + outputDir + "\n"); }
250 vector<string> inputFileNames;
251 if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile); }
252 else { inputFileNames.push_back(sabundfile); }
254 for (int p = 0; p < inputFileNames.size(); p++) {
255 if (inputFileNames.size() > 1) {
256 m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
259 InputData input(inputFileNames[p], "sabund");
260 SAbundVector* sabund = input.getSAbundVector();
261 string lastLabel = sabund->getLabel();
263 set<string> processedLabels;
264 set<string> userLabels = labels;
266 map<string, string> variables;
267 variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p]));
268 string summaryfilename = getOutputFileName("summary", variables);
269 summaryfilename = m->getFullPathName(summaryfilename);
271 if (m->debug) { m->mothurOut("[DEBUG]: Input File = " + inputFileNames[p] + ".\n[DEBUG]: inputdata address = " + toString(&input) + ".\n[DEBUG]: sabund address = " + toString(&sabund) + ".\n"); }
274 m->openOutputFile(summaryfilename, out);
276 out << "label\tmodel\testimate\tlci\tuci" << endl;
278 if (m->debug) { string open = "no"; if (out.is_open()) { open = "yes"; } m->mothurOut("[DEBUG]: output stream is open = " + open + ".\n"); }
280 //for each label the user selected
281 while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
284 if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
285 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
287 //create catchall input file from mothur's inputfile
288 string filename = process(sabund, inputFileNames[p]);
289 string outputPath = m->getPathName(filename);
291 //create system command
292 string catchAllCommand = "";
293 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
294 catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
296 //removes extra '\\' catchall doesnt like that
297 vector<string> tempNames;
298 string tempFilename = filename;
299 m->splitAtDash(tempFilename, tempNames);
300 tempFilename = tempNames[0];
302 string tempOutputPath = outputPath;
303 m->splitAtDash(tempOutputPath, tempNames);
304 tempOutputPath = tempNames[0];
305 if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
306 catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \"" + tempOutputPath + "\" 1";
307 catchAllCommand = "\"" + catchAllCommand + "\"";
310 if (m->debug) { m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
313 system(catchAllCommand.c_str());
315 if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
317 if (!m->debug) { m->mothurRemove(filename); }
320 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
321 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
323 variables["[filename]"] = filename;
324 outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
325 outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
326 outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
327 outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
329 if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
331 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
333 if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
335 if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]); } delete sabund; return 0; }
337 processedLabels.insert(sabund->getLabel());
338 userLabels.erase(sabund->getLabel());
341 if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
342 string saveLabel = sabund->getLabel();
345 sabund = (input.getSAbundVector(lastLabel));
347 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
350 //create catchall input file from mothur's inputfile
351 string filename = process(sabund, inputFileNames[p]);
352 string outputPath = m->getPathName(filename);
354 //create system command
355 string catchAllCommand = "";
356 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
357 catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
359 //removes extra '\\' catchall doesnt like that
360 vector<string> tempNames;
361 string tempFilename = filename;
362 m->splitAtDash(tempFilename, tempNames);
363 tempFilename = tempNames[0];
365 string tempOutputPath = outputPath;
366 m->splitAtDash(tempOutputPath, tempNames);
367 tempOutputPath = tempNames[0];
368 if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
369 catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \"" + tempOutputPath + "\" 1";
370 catchAllCommand = "\"" + catchAllCommand + "\"";
373 if (m->debug) { m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
376 system(catchAllCommand.c_str());
378 if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
380 if (!m->debug) { m->mothurRemove(filename); }
383 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
384 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
386 variables["[filename]"] = filename;
387 outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
388 outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
389 outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
390 outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
393 if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
395 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
397 if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
399 if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]); } delete sabund; return 0; }
401 processedLabels.insert(sabund->getLabel());
402 userLabels.erase(sabund->getLabel());
404 //restore real lastlabel to save below
405 sabund->setLabel(saveLabel);
409 lastLabel = sabund->getLabel();
412 sabund = (input.getSAbundVector());
415 //output error messages about any remaining user labels
416 set<string>::iterator it;
417 bool needToRun = false;
418 for (it = userLabels.begin(); it != userLabels.end(); it++) {
419 m->mothurOut("Your file does not include the label " + *it);
420 if (processedLabels.count(lastLabel) != 1) {
421 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
424 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
428 //run last label if you need to
429 if (needToRun == true) {
430 if (sabund != NULL) { delete sabund; }
431 sabund = (input.getSAbundVector(lastLabel));
433 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
435 //create catchall input file from mothur's inputfile
436 string filename = process(sabund, inputFileNames[p]);
437 string outputPath = m->getPathName(filename);
439 //create system command
440 string catchAllCommand = "";
441 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
442 catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
444 //removes extra '\\' catchall doesnt like that
445 vector<string> tempNames;
446 string tempFilename = filename;
447 m->splitAtDash(tempFilename, tempNames);
448 tempFilename = tempNames[0];
450 string tempOutputPath = outputPath;
451 m->splitAtDash(tempOutputPath, tempNames);
452 tempOutputPath = tempNames[0];
453 if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); }
454 catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \"" + tempOutputPath + "\" 1";
455 catchAllCommand = "\"" + catchAllCommand + "\"";
458 if (m->debug) { m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
461 system(catchAllCommand.c_str());
463 if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
465 if (!m->debug) { m->mothurRemove(filename); }
467 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
468 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
470 variables["[filename]"] = filename;
471 outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables));
472 outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables));
473 outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables));
474 outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables));
475 if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
477 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
479 if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
486 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]); } return 0; }
490 if (sharedfile == "") {
491 string summaryfilename = savedOutputDir + m->getRootName(m->getSimpleName(inputFileNames[0])) + "catchall.summary";
492 summaryfilename = m->getFullPathName(summaryfilename);
493 outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
494 }else { //combine summaries
495 vector<string> sumNames;
496 for (int i = 0; i < inputFileNames.size(); i++) {
497 sumNames.push_back(m->getFullPathName(outputDir + m->getRootName(m->getSimpleName(inputFileNames[i])) + "catchall.summary"));
499 string summaryfilename = combineSummmary(sumNames);
500 outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
503 m->mothurOutEndLine();
504 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
505 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
506 m->mothurOutEndLine();
511 catch(exception& e) {
512 m->errorOut(e, "CatchAllCommand", "execute");
516 //**********************************************************************************************************************
517 string CatchAllCommand::process(SAbundVector* sabund, string file1) {
519 map<string, string> variables;
520 variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(file1));
521 variables["[distance]"] = sabund->getLabel();
522 string filename = getOutputFileName("sabund", variables);
523 filename = m->getFullPathName(filename);
526 m->openOutputFile(filename, out);
528 if (m->debug) { m->mothurOut("[DEBUG]: Creating " + filename + " file for catchall, shown below.\n\n"); }
530 for (int i = 1; i <= sabund->getMaxRank(); i++) {
531 int temp = sabund->get(i);
534 out << i << "," << temp << endl;
535 if (m->debug) { m->mothurOut(toString(i) + "," + toString(temp) + "\n"); }
540 if (m->debug) { m->mothurOut("[DEBUG]: Done creating " + filename + " file for catchall, shown above.\n\n"); }
545 catch(exception& e) {
546 m->errorOut(e, "CatchAllCommand", "process");
550 //*********************************************************************************************************************
551 string CatchAllCommand::combineSummmary(vector<string>& outputNames) {
555 map<string, string> variables;
556 variables["[filename]"] = savedOutputDir + m->getRootName(m->getSimpleName(sharedfile));
557 string combineFileName = getOutputFileName("summary", variables);
560 m->openOutputFile(combineFileName, out);
562 out << "label\tgroup\tmodel\testimate\tlci\tuci" << endl;
564 //open each groups summary file
565 string newLabel = "";
567 map<string, vector<string> > files;
568 for (int i=0; i<outputNames.size(); i++) {
569 vector<string> thisFilesLines;
572 m->openInputFile(outputNames[i], temp);
574 //read through first line - labels
579 while (!temp.eof()) {
581 string thisLine = "";
584 for (int j = 0; j < 5; j++) {
588 if (j == 1) { thisLine += groups[i] + "\t" + tempLabel + "\t"; }
589 else{ thisLine += tempLabel + "\t"; }
594 thisFilesLines.push_back(thisLine);
599 files[outputNames[i]] = thisFilesLines;
601 numLines = thisFilesLines.size();
604 m->mothurRemove(outputNames[i]);
608 for (int k = 0; k < numLines; k++) {
610 //grab summary data for each group
611 for (int i=0; i<outputNames.size(); i++) {
612 out << files[outputNames[i]][k];
619 //return combine file name
620 return combineFileName;
623 catch(exception& e) {
624 m->errorOut(e, "CatchAllCommand", "combineSummmary");
628 //**********************************************************************************************************************
629 int CatchAllCommand::createSummaryFile(string file1, string label, ofstream& out) {
633 int able = m->openInputFile(file1, in, "noerror");
635 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; }
639 string header = m->getline(in); m->gobble(in);
641 int pos = header.find("Total Number of Observed Species =");
642 string numString = "";
645 if (pos == string::npos) { m->mothurOut("[ERROR]: cannot parse " + file1); m->mothurOutEndLine(); }
647 //pos will be the position of the T in total, so we want to count to the position of =
658 if (pos > header.length()) { m->mothurOut("Cannot find number of OTUs in " + file1); m->mothurOutEndLine(); in.close(); return 0; }
662 string firstline = m->getline(in); m->gobble(in);
663 vector<string> values;
664 m->splitAtComma(firstline, values);
666 values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
668 if (values.size() == 1) { //grab next line if firstline didn't have what you wanted
669 string secondline = m->getline(in); m->gobble(in);
671 m->splitAtComma(secondline, values);
673 values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
676 if (values.size() == 1) { //still not what we wanted fill values with numOTUs
677 values.resize(8, "");
679 values[4] = numString;
680 values[6] = numString;
681 values[7] = numString;
684 if (values.size() < 8) { values.resize(8, ""); }
686 out << label << '\t' << values[1] << '\t' << values[4] << '\t' << values[6] << '\t' << values[7] << endl;
694 catch(exception& e) {
695 m->errorOut(e, "CatchAllCommand", "createSummaryFile");
699 //**********************************************************************************************************************
700 vector<string> CatchAllCommand::parseSharedFile(string filename) {
702 vector<string> filenames;
705 InputData input(filename, "sharedfile");
706 vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
708 string sharedFileRoot = outputDir + m->getRootName(m->getSimpleName(filename));
710 //clears file before we start to write to it below
711 for (int i=0; i<lookup.size(); i++) {
712 m->mothurRemove((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
713 filenames.push_back((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
714 groups.push_back(lookup[i]->getGroup());
717 while(lookup[0] != NULL) {
719 for (int i = 0; i < lookup.size(); i++) {
720 SAbundVector sav = lookup[i]->getSAbundVector();
722 m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".sabund", out);
727 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
728 lookup = input.getSharedRAbundVectors();
733 catch(exception& e) {
734 m->errorOut(e, "CatchAllCommand", "parseSharedFile");
738 /**************************************************************************************/