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",false,false); parameters.push_back(pshared);
18 CommandParameter psabund("sabund", "InputTypes", "", "", "catchallInputs", "catchallInputs", "none",false,false); 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::getOutputFileNameTag(string type, string inputName=""){
54 string outputFileName = "";
55 map<string, vector<string> >::iterator it;
57 //is this a type this command creates
58 it = outputTypes.find(type);
59 if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
61 if (type == "csv") { outputFileName = "csv"; }
62 else if (type == "summary") { outputFileName = "catchall.summary"; }
63 else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; }
65 return outputFileName;
68 m->errorOut(e, "CatchAllCommand", "getOutputFileNameTag");
72 //**********************************************************************************************************************
73 CatchAllCommand::CatchAllCommand(){
75 abort = true; calledHelp = true;
77 //initialize outputTypes
78 vector<string> tempOutNames;
79 outputTypes["csv"] = tempOutNames;
80 outputTypes["summary"] = tempOutNames;
83 m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
87 /**************************************************************************************/
88 CatchAllCommand::CatchAllCommand(string option) {
91 abort = false; calledHelp = false;
94 //allow user to run help
95 if(option == "help") { help(); abort = true; calledHelp = true; }
96 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
99 vector<string> myArray = setParameters();
101 OptionParser parser(option);
102 map<string,string> parameters = parser.getParameters();
104 ValidParameters validParameter;
105 map<string, string>::iterator it;
107 //check to make sure all parameters are valid for command
108 for (it = parameters.begin(); it != parameters.end(); it++) {
109 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
112 //initialize outputTypes
113 vector<string> tempOutNames;
114 outputTypes["csv"] = tempOutNames;
115 outputTypes["summary"] = tempOutNames;
117 //if the user changes the input directory command factory will send this info to us in the output parameter
118 string inputDir = validParameter.validFile(parameters, "inputdir", false);
119 if (inputDir == "not found"){ inputDir = ""; }
122 it = parameters.find("sabund");
123 //user has given a template file
124 if(it != parameters.end()){
125 path = m->hasPath(it->second);
126 //if the user has not given a path then, add inputdir. else leave path alone.
127 if (path == "") { parameters["sabund"] = inputDir + it->second; }
130 it = parameters.find("shared");
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["shared"] = inputDir + it->second; }
139 //check for required parameters
140 sabundfile = validParameter.validFile(parameters, "sabund", true);
141 if (sabundfile == "not open") { sabundfile = ""; abort = true; }
142 else if (sabundfile == "not found") { sabundfile = ""; }
143 else { m->setSabundFile(sabundfile); }
145 sharedfile = validParameter.validFile(parameters, "shared", true);
146 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
147 else if (sharedfile == "not found") { sharedfile = ""; }
148 else { m->setSharedFile(sharedfile); }
150 string label = validParameter.validFile(parameters, "label", false);
151 if (label == "not found") { label = ""; }
153 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
154 else { allLines = 1; }
157 if ((sharedfile == "") && (sabundfile == "")) {
158 //is there are current file available for either of these?
159 //give priority to shared, then sabund
160 //if there is a current shared file, use it
161 sharedfile = m->getSharedFile();
162 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
164 sabundfile = m->getSabundFile();
165 if (sabundfile != "") { m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); }
167 m->mothurOut("No valid current files. You must provide a sabund or shared file before you can use the catchall command."); m->mothurOutEndLine();
173 //if the user changes the output directory command factory will send this info to us in the output parameter
174 outputDir = validParameter.validFile(parameters, "outputdir", false);
175 if (outputDir == "not found"){
176 if (sabundfile != "") { outputDir = m->hasPath(sabundfile); }
177 else { outputDir = m->hasPath(sharedfile); }
182 catch(exception& e) {
183 m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
187 /**************************************************************************************/
188 int CatchAllCommand::execute() {
191 if (abort == true) { if (calledHelp) { return 0; } return 2; }
193 //get location of catchall
195 path = path.substr(0, (path.find_last_of("othur")-5));
196 path = m->getFullPathName(path);
198 if (m->debug) { m->mothurOut("[DEBUG]: mothur's path = " + path + "\n"); }
200 savedOutputDir = outputDir;
201 string catchAllCommandExe = "";
202 string catchAllTest = "";
203 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
204 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.
205 catchAllTest = path + "CatchAllcmdL.exe";
207 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.
208 catchAllTest = path + "CatchAllcmdW.exe";
211 //test to make sure formatdb exists
213 catchAllTest = m->getFullPathName(catchAllTest);
214 int ableToOpen = m->openInputFile(catchAllTest, in, "no error"); in.close();
215 if(ableToOpen == 1) {
216 m->mothurOut(catchAllTest + " file does not exist. Checking path... \n");
217 //check to see if uchime is in the path??
219 string programName = "CatchAllcmdW.exe";
220 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
221 programName = "CatchAllcmdL.exe";
223 string cLocation = m->findProgramPath(programName);
226 ableToOpen = m->openInputFile(cLocation, in2, "no error"); in2.close();
228 if(ableToOpen == 1) { m->mothurOut("[ERROR]: " + cLocation + " file does not exist. mothur requires the catchall executable."); m->mothurOutEndLine(); return 0; }
229 else { m->mothurOut("Found catchall in your path, using " + cLocation + "\n"); catchAllTest = cLocation; }
231 catchAllTest = m->getFullPathName(catchAllTest);
233 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
234 catchAllCommandExe += "mono " + catchAllTest + " ";
236 catchAllCommandExe += "\"" + catchAllTest + "\" ";
239 //prepare full output directory
240 outputDir = m->getFullPathName(outputDir);
242 if (m->debug) { m->mothurOut("[DEBUG]: catchall location = " + catchAllCommandExe + "\n[DEBUG]: outputDir = " + outputDir + "\n"); }
244 vector<string> inputFileNames;
245 if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile); }
246 else { inputFileNames.push_back(sabundfile); }
248 for (int p = 0; p < inputFileNames.size(); p++) {
249 if (inputFileNames.size() > 1) {
250 m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
253 InputData input(inputFileNames[p], "sabund");
254 SAbundVector* sabund = input.getSAbundVector();
255 string lastLabel = sabund->getLabel();
257 set<string> processedLabels;
258 set<string> userLabels = labels;
260 string summaryfilename = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + getOutputFileNameTag("summary");
261 summaryfilename = m->getFullPathName(summaryfilename);
263 if (m->debug) { m->mothurOut("[DEBUG]: Input File = " + inputFileNames[p] + ".\n[DEBUG]: inputdata address = " + toString(&input) + ".\n[DEBUG]: sabund address = " + toString(&sabund) + ".\n"); }
266 m->openOutputFile(summaryfilename, out);
268 out << "label\tmodel\testimate\tlci\tuci" << endl;
270 if (m->debug) { string open = "no"; if (out.is_open()) { open = "yes"; } m->mothurOut("[DEBUG]: output stream is open = " + open + ".\n"); }
272 //for each label the user selected
273 while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
276 if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
277 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
279 //create catchall input file from mothur's inputfile
280 string filename = process(sabund, inputFileNames[p]);
281 string outputPath = m->getPathName(filename);
283 //create system command
284 string catchAllCommand = "";
285 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
286 catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
288 if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); }
289 catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \"" + outputPath + "\" 1";
290 //wrap entire string in ""
291 catchAllCommand = "\"" + catchAllCommand + "\"";
294 if (m->debug) { m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
297 system(catchAllCommand.c_str());
299 if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
301 if (!m->debug) { m->mothurRemove(filename); }
304 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
305 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
307 outputNames.push_back(filename + "_Analysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_Analysis." + getOutputFileNameTag("csv"));
308 outputNames.push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv"));
309 outputNames.push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv"));
310 outputNames.push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv"));
312 if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
314 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
316 if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
318 if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]); } delete sabund; return 0; }
320 processedLabels.insert(sabund->getLabel());
321 userLabels.erase(sabund->getLabel());
324 if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
325 string saveLabel = sabund->getLabel();
328 sabund = (input.getSAbundVector(lastLabel));
330 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
333 //create catchall input file from mothur's inputfile
334 string filename = process(sabund, inputFileNames[p]);
335 string outputPath = m->getPathName(filename);
337 //create system command
338 string catchAllCommand = "";
339 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
340 catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
342 if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); }
343 catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \"" + outputPath + "\" 1";
344 catchAllCommand = "\"" + catchAllCommand + "\"";
347 if (m->debug) { m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
350 system(catchAllCommand.c_str());
352 if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
354 if (!m->debug) { m->mothurRemove(filename); }
357 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
358 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
360 outputNames.push_back(filename + "_Analysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_Analysis." + getOutputFileNameTag("csv"));
361 outputNames.push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv"));
362 outputNames.push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv"));
363 outputNames.push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv"));
366 if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
368 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
370 if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
372 if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]); } delete sabund; return 0; }
374 processedLabels.insert(sabund->getLabel());
375 userLabels.erase(sabund->getLabel());
377 //restore real lastlabel to save below
378 sabund->setLabel(saveLabel);
382 lastLabel = sabund->getLabel();
385 sabund = (input.getSAbundVector());
388 //output error messages about any remaining user labels
389 set<string>::iterator it;
390 bool needToRun = false;
391 for (it = userLabels.begin(); it != userLabels.end(); it++) {
392 m->mothurOut("Your file does not include the label " + *it);
393 if (processedLabels.count(lastLabel) != 1) {
394 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
397 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
401 //run last label if you need to
402 if (needToRun == true) {
403 if (sabund != NULL) { delete sabund; }
404 sabund = (input.getSAbundVector(lastLabel));
406 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
408 //create catchall input file from mothur's inputfile
409 string filename = process(sabund, inputFileNames[p]);
410 string outputPath = m->getPathName(filename);
412 //create system command
413 string catchAllCommand = "";
414 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
415 catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
417 if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); }
418 catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \"" + outputPath + "\" 1";
419 catchAllCommand = "\"" + catchAllCommand + "\"";
422 if (m->debug) { m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
425 system(catchAllCommand.c_str());
427 if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
429 if (!m->debug) { m->mothurRemove(filename); }
431 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
432 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
434 outputNames.push_back(filename + "_Analysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_Analysis." + getOutputFileNameTag("csv"));
435 outputNames.push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv"));
436 outputNames.push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv"));
437 outputNames.push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv")); if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
439 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
441 if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
448 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]); } return 0; }
452 if (sharedfile == "") {
453 string summaryfilename = savedOutputDir + m->getRootName(m->getSimpleName(inputFileNames[0])) + "catchall.summary";
454 summaryfilename = m->getFullPathName(summaryfilename);
455 outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
456 }else { //combine summaries
457 vector<string> sumNames;
458 for (int i = 0; i < inputFileNames.size(); i++) {
459 sumNames.push_back(m->getFullPathName(outputDir + m->getRootName(m->getSimpleName(inputFileNames[i])) + "catchall.summary"));
461 string summaryfilename = combineSummmary(sumNames);
462 outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
465 m->mothurOutEndLine();
466 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
467 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
468 m->mothurOutEndLine();
473 catch(exception& e) {
474 m->errorOut(e, "CatchAllCommand", "execute");
478 //**********************************************************************************************************************
479 string CatchAllCommand::process(SAbundVector* sabund, string file1) {
481 string filename = outputDir + m->getRootName(m->getSimpleName(file1)) + sabund->getLabel() + ".csv";
482 filename = m->getFullPathName(filename);
485 m->openOutputFile(filename, out);
487 if (m->debug) { m->mothurOut("[DEBUG]: Creating " + filename + " file for catchall, shown below.\n\n"); }
489 for (int i = 1; i <= sabund->getMaxRank(); i++) {
490 int temp = sabund->get(i);
493 out << i << "," << temp << endl;
494 if (m->debug) { m->mothurOut(toString(i) + "," + toString(temp) + "\n"); }
499 if (m->debug) { m->mothurOut("[DEBUG]: Done creating " + filename + " file for catchall, shown above.\n\n"); }
504 catch(exception& e) {
505 m->errorOut(e, "CatchAllCommand", "process");
509 //*********************************************************************************************************************
510 string CatchAllCommand::combineSummmary(vector<string>& outputNames) {
514 string combineFileName = savedOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("summary");
517 m->openOutputFile(combineFileName, out);
519 out << "label\tgroup\tmodel\testimate\tlci\tuci" << endl;
521 //open each groups summary file
522 string newLabel = "";
524 map<string, vector<string> > files;
525 for (int i=0; i<outputNames.size(); i++) {
526 vector<string> thisFilesLines;
529 m->openInputFile(outputNames[i], temp);
531 //read through first line - labels
536 while (!temp.eof()) {
538 string thisLine = "";
541 for (int j = 0; j < 5; j++) {
545 if (j == 1) { thisLine += groups[i] + "\t" + tempLabel + "\t"; }
546 else{ thisLine += tempLabel + "\t"; }
551 thisFilesLines.push_back(thisLine);
556 files[outputNames[i]] = thisFilesLines;
558 numLines = thisFilesLines.size();
561 m->mothurRemove(outputNames[i]);
565 for (int k = 0; k < numLines; k++) {
567 //grab summary data for each group
568 for (int i=0; i<outputNames.size(); i++) {
569 out << files[outputNames[i]][k];
576 //return combine file name
577 return combineFileName;
580 catch(exception& e) {
581 m->errorOut(e, "CatchAllCommand", "combineSummmary");
585 //**********************************************************************************************************************
586 int CatchAllCommand::createSummaryFile(string file1, string label, ofstream& out) {
590 int able = m->openInputFile(file1, in, "noerror");
592 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; }
596 string header = m->getline(in); m->gobble(in);
598 int pos = header.find("Total Number of Observed Species =");
599 string numString = "";
602 if (pos == string::npos) { m->mothurOut("[ERROR]: cannot parse " + file1); m->mothurOutEndLine(); }
604 //pos will be the position of the T in total, so we want to count to the position of =
615 if (pos > header.length()) { m->mothurOut("Cannot find number of OTUs in " + file1); m->mothurOutEndLine(); in.close(); return 0; }
619 string firstline = m->getline(in); m->gobble(in);
620 vector<string> values;
621 m->splitAtComma(firstline, values);
623 values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
625 if (values.size() == 1) { //grab next line if firstline didn't have what you wanted
626 string secondline = m->getline(in); m->gobble(in);
628 m->splitAtComma(secondline, values);
630 values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
633 if (values.size() == 1) { //still not what we wanted fill values with numOTUs
634 values.resize(8, "");
636 values[4] = numString;
637 values[6] = numString;
638 values[7] = numString;
641 if (values.size() < 8) { values.resize(8, ""); }
643 out << label << '\t' << values[1] << '\t' << values[4] << '\t' << values[6] << '\t' << values[7] << endl;
651 catch(exception& e) {
652 m->errorOut(e, "CatchAllCommand", "createSummaryFile");
656 //**********************************************************************************************************************
657 vector<string> CatchAllCommand::parseSharedFile(string filename) {
659 vector<string> filenames;
662 InputData input(filename, "sharedfile");
663 vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
665 string sharedFileRoot = outputDir + m->getRootName(m->getSimpleName(filename));
667 //clears file before we start to write to it below
668 for (int i=0; i<lookup.size(); i++) {
669 m->mothurRemove((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
670 filenames.push_back((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
671 groups.push_back(lookup[i]->getGroup());
674 while(lookup[0] != NULL) {
676 for (int i = 0; i < lookup.size(); i++) {
677 SAbundVector sav = lookup[i]->getSAbundVector();
679 m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".sabund", out);
684 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
685 lookup = input.getSharedRAbundVectors();
690 catch(exception& e) {
691 m->errorOut(e, "CatchAllCommand", "parseSharedFile");
695 /**************************************************************************************/