]> git.donarmstrong.com Git - mothur.git/blob - catchallcommand.cpp
Merge remote-tracking branch 'mothur/master'
[mothur.git] / catchallcommand.cpp
1 /*
2  *  catchallcommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 5/11/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "catchallcommand.h"
11
12 //**********************************************************************************************************************
13 vector<string> CatchAllCommand::setParameters(){        
14         try {
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);
21                 
22                 vector<string> myArray;
23                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
24                 return myArray;
25         }
26         catch(exception& e) {
27                 m->errorOut(e, "CatchAllCommand", "setParameters");
28                 exit(1);
29         }
30 }
31 //**********************************************************************************************************************
32 string CatchAllCommand::getHelpString(){        
33         try {
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";      
44                 return helpString;
45         }
46         catch(exception& e) {
47                 m->errorOut(e, "CatchAllCommand", "getHelpString");
48                 exit(1);
49         }
50 }
51 //**********************************************************************************************************************
52 CatchAllCommand::CatchAllCommand(){     
53         try {
54                 abort = true; calledHelp = true;
55                 setParameters();
56                 //initialize outputTypes
57                 vector<string> tempOutNames;
58                 outputTypes["csv"] = tempOutNames;
59                 outputTypes["summary"] = tempOutNames;
60         }
61         catch(exception& e) {
62                 m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
63                 exit(1);
64         }
65 }
66 /**************************************************************************************/
67 CatchAllCommand::CatchAllCommand(string option)  {      
68         try {
69                 
70                 abort = false; calledHelp = false;   
71                 allLines = 1;
72                 
73                 //allow user to run help
74                 if(option == "help") { help(); abort = true; calledHelp = true; }
75                 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
76                 
77                 else {
78                         vector<string> myArray = setParameters();
79                         
80                         OptionParser parser(option);
81                         map<string,string> parameters = parser.getParameters();
82                         
83                         ValidParameters validParameter;
84                         map<string, string>::iterator it;
85                 
86                         //check to make sure all parameters are valid for command
87                         for (it = parameters.begin(); it != parameters.end(); it++) { 
88                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
89                         }
90                         
91                         //initialize outputTypes
92                         vector<string> tempOutNames;
93                         outputTypes["csv"] = tempOutNames;
94                         outputTypes["summary"] = tempOutNames;
95                         
96                         //if the user changes the input directory command factory will send this info to us in the output parameter 
97                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
98                         if (inputDir == "not found"){   inputDir = "";          }
99                         else {
100                                 string path;
101                                 it = parameters.find("sabund");
102                                 //user has given a template file
103                                 if(it != parameters.end()){ 
104                                         path = m->hasPath(it->second);
105                                         //if the user has not given a path then, add inputdir. else leave path alone.
106                                         if (path == "") {       parameters["sabund"] = inputDir + it->second;           }
107                                 }
108                                 
109                                 it = parameters.find("shared");
110                                 //user has given a template file
111                                 if(it != parameters.end()){ 
112                                         path = m->hasPath(it->second);
113                                         //if the user has not given a path then, add inputdir. else leave path alone.
114                                         if (path == "") {       parameters["shared"] = inputDir + it->second;           }
115                                 }
116                         }
117
118                         //check for required parameters
119                         sabundfile = validParameter.validFile(parameters, "sabund", true);
120                         if (sabundfile == "not open") { sabundfile = ""; abort = true; }
121                         else if (sabundfile == "not found") { sabundfile = "";  }
122                         else { m->setSabundFile(sabundfile); }
123                         
124                         sharedfile = validParameter.validFile(parameters, "shared", true);
125                         if (sharedfile == "not open") { sharedfile = ""; abort = true; }
126                         else if (sharedfile == "not found") { sharedfile = "";   }
127                         else { m->setSharedFile(sharedfile); }
128                         
129                         string label = validParameter.validFile(parameters, "label", false);                    
130                         if (label == "not found") { label = ""; }
131                         else { 
132                                 if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
133                                 else { allLines = 1;  }
134                         }
135                 
136                         if ((sharedfile == "") && (sabundfile == "")) { 
137                                 //is there are current file available for either of these?
138                                 //give priority to shared, then sabund
139                                 //if there is a current shared file, use it
140                                 sharedfile = m->getSharedFile(); 
141                                 if (sharedfile != "") {  m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
142                                 else { 
143                                         sabundfile = m->getSabundFile(); 
144                                         if (sabundfile != "") {  m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); }
145                                         else { 
146                                                 m->mothurOut("No valid current files. You must provide a sabund or shared file before you can use the catchall command."); m->mothurOutEndLine(); 
147                                                 abort = true;
148                                         }
149                                 }
150                         }
151                         
152                         //if the user changes the output directory command factory will send this info to us in the output parameter 
153                         outputDir = validParameter.validFile(parameters, "outputdir", false);           
154                         if (outputDir == "not found"){  
155                                 if (sabundfile != "") {  outputDir = m->hasPath(sabundfile); }
156                                 else { outputDir = m->hasPath(sharedfile); }
157                         }
158                 }
159
160         }
161         catch(exception& e) {
162                 m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
163                 exit(1);
164         }
165 }
166 /**************************************************************************************/
167 int CatchAllCommand::execute() {        
168         try {
169                 
170                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
171                 
172                 //get location of catchall
173                 path = m->argv;
174                 path = path.substr(0, (path.find_last_of("othur")-5));
175                 path = m->getFullPathName(path);
176                 
177                 savedOutputDir = outputDir;
178                 string catchAllCommandExe = ""; 
179                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
180                         catchAllCommandExe += "mono " + path + "CatchAllcmdL.exe ";
181                         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.
182                 #else
183                         catchAllCommandExe += "\"" + path + "CatchAllcmdW.exe\"" + " ";
184                         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.
185                 #endif
186                 
187                 //prepare full output directory
188                 outputDir = m->getFullPathName(outputDir);
189                 
190                 vector<string> inputFileNames;
191                 if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile);   }
192                 else {  inputFileNames.push_back(sabundfile);  }                
193                 
194                 for (int p = 0; p < inputFileNames.size(); p++) {
195                         if (inputFileNames.size() > 1) {
196                                 m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
197                         }
198                         
199                         InputData* input = new InputData(inputFileNames[p], "sabund");
200                         SAbundVector* sabund = input->getSAbundVector();
201                         string lastLabel = sabund->getLabel();
202                                                         
203                         set<string> processedLabels;
204                         set<string> userLabels = labels;
205                         
206                         string summaryfilename = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "catchall.summary";
207                         summaryfilename = m->getFullPathName(summaryfilename);
208                         
209                         ofstream out;
210                         m->openOutputFile(summaryfilename, out);        
211                         
212                         out << "label\tmodel\testimate\tlci\tuci" << endl;
213                         
214                         //for each label the user selected
215                         while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
216                                 
217                                                 
218                                 if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
219                                                 m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
220                                                 
221                                                 //create catchall input file from mothur's inputfile
222                                                 string filename = process(sabund, inputFileNames[p]);
223                                                 string outputPath = m->getPathName(filename);
224                                                                                         
225                                                 //create system command
226                                                 string catchAllCommand = "";
227                                                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
228                                                         catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
229                                                 #else
230                                                         if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); }
231                                                         catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + "\" 1";
232                                                         //wrap entire string in ""
233                                                         catchAllCommand = "\"" + catchAllCommand + "\"";
234                                                 #endif
235                                         
236                                                 //run catchall
237                                                 system(catchAllCommand.c_str());
238                                         
239                                                 m->mothurRemove(filename);
240                                         
241                                                 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
242                                                 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
243                                         
244                                                 outputNames.push_back(filename + "_Analysis.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv");
245                                                 outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv");
246                                                 outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv");
247                                                 outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv");
248                                         
249                                                 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
250                                                                                         
251                                                 if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);   }  delete input;  delete sabund;  return 0; }
252
253                                                 processedLabels.insert(sabund->getLabel());
254                                                 userLabels.erase(sabund->getLabel());
255                                 }
256                                 
257                                 if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
258                                                 string saveLabel = sabund->getLabel();
259                                                 
260                                                 delete sabund;          
261                                                 sabund = (input->getSAbundVector(lastLabel));
262                                                 
263                                                 m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
264                                                 
265
266                                                 //create catchall input file from mothur's inputfile
267                                                 string filename = process(sabund, inputFileNames[p]);
268                                                 string outputPath = m->getPathName(filename);
269                                                                                         
270                                                 //create system command
271                                                 string catchAllCommand = "";
272                                                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
273                                                         catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
274                                                 #else
275                                                         if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); }
276                                                         catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + "\" 1";
277                                                         catchAllCommand = "\"" + catchAllCommand + "\"";
278                                                 #endif
279
280                                                 //run catchall
281                                                 system(catchAllCommand.c_str());
282                                         
283                                                 m->mothurRemove(filename);
284                                         
285                                                 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
286                                                 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
287                                         
288                                                 outputNames.push_back(filename + "_Analysis.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv");
289                                                 outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv");
290                                                 outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv");
291                                                 outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv");
292                                         
293                                                 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
294                                         
295                                                 if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);   }  delete input;  delete sabund;  return 0; }
296
297                                                 processedLabels.insert(sabund->getLabel());
298                                                 userLabels.erase(sabund->getLabel());
299                                                 
300                                                 //restore real lastlabel to save below
301                                                 sabund->setLabel(saveLabel);
302                                 }
303                                 
304                                 
305                                 lastLabel = sabund->getLabel(); 
306                                 
307                                 delete sabund;          
308                                 sabund = (input->getSAbundVector());
309                         }
310                         
311                         //output error messages about any remaining user labels
312                         set<string>::iterator it;
313                         bool needToRun = false;
314                         for (it = userLabels.begin(); it != userLabels.end(); it++) {  
315                                 m->mothurOut("Your file does not include the label " + *it); 
316                                 if (processedLabels.count(lastLabel) != 1) {
317                                         m->mothurOut(". I will use " + lastLabel + ".");  m->mothurOutEndLine();
318                                         needToRun = true;
319                                 }else {
320                                         m->mothurOut(". Please refer to " + lastLabel + ".");  m->mothurOutEndLine();
321                                 }
322                         }
323                         
324                         //run last label if you need to
325                         if (needToRun == true)  {
326                                 if (sabund != NULL) {   delete sabund;  }
327                                 sabund = (input->getSAbundVector(lastLabel));
328                                 
329                                 m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
330                                 
331                                 //create catchall input file from mothur's inputfile
332                                 string filename = process(sabund, inputFileNames[p]);
333                                 string outputPath = m->getPathName(filename);
334                                 
335                                 //create system command
336                                 string catchAllCommand = "";
337                                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
338                                         catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1";
339                                 #else
340                                         if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); }
341                                         catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + "\" 1";
342                                         catchAllCommand = "\"" + catchAllCommand + "\"";
343                                 #endif
344                                 
345                                 //run catchall
346                                 system(catchAllCommand.c_str());
347                                 
348                                 m->mothurRemove(filename);
349                                 
350                                 filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
351                                 if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
352                                 
353                                 outputNames.push_back(filename + "_Analysis.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv");
354                                 outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv");
355                                 outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv");
356                                 outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv");        
357                                 
358                                 createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
359                                 
360                                 delete sabund;
361                         }
362                         
363                         out.close();
364                         delete input; 
365                         
366                         if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);        } return 0; }
367                                 
368                 }
369                 
370                 if (sharedfile == "") {  
371                         string summaryfilename = savedOutputDir + m->getRootName(m->getSimpleName(inputFileNames[0])) + "catchall.summary";
372                         summaryfilename = m->getFullPathName(summaryfilename);
373                         outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
374                 }else { //combine summaries
375                         vector<string> sumNames;
376                         for (int i = 0; i < inputFileNames.size(); i++) {
377                                 sumNames.push_back(m->getFullPathName(outputDir + m->getRootName(m->getSimpleName(inputFileNames[i])) + "catchall.summary"));
378                         }
379                         string summaryfilename = combineSummmary(sumNames);
380                         outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
381                 }
382                 
383                 m->mothurOutEndLine();
384                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
385                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }       
386                 m->mothurOutEndLine();
387                 
388
389                 return 0;
390         }
391         catch(exception& e) {
392                 m->errorOut(e, "CatchAllCommand", "execute");
393                 exit(1);
394         }
395 }
396 //**********************************************************************************************************************
397 string CatchAllCommand::process(SAbundVector* sabund, string file1) {
398         try {
399                 string filename = outputDir + m->getRootName(m->getSimpleName(file1)) + sabund->getLabel() + ".csv";
400                 filename = m->getFullPathName(filename);
401         
402                 ofstream out;
403                 m->openOutputFile(filename, out);
404                 
405                 for (int i = 1; i <= sabund->getMaxRank(); i++) {
406                         int temp = sabund->get(i);
407                         
408                         if (temp != 0) {
409                                 out << i << "," << temp << endl;
410                         }
411                 }
412                 out.close();
413                 
414                 return filename;
415         
416         }
417         catch(exception& e) {
418                 m->errorOut(e, "CatchAllCommand", "process");
419                 exit(1);
420         }
421 }
422 //*********************************************************************************************************************
423 string CatchAllCommand::combineSummmary(vector<string>& outputNames) {
424         try {
425                 
426                 ofstream out;
427                 string combineFileName = savedOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + "catchall.summary";
428                 
429                 //open combined file
430                 m->openOutputFile(combineFileName, out);
431                 
432                 out << "label\tgroup\tmodel\testimate\tlci\tuci" << endl;
433                 
434                 //open each groups summary file
435                 string newLabel = "";
436                 int numLines = 0;
437                 map<string, vector<string> > files;
438                 for (int i=0; i<outputNames.size(); i++) {
439                         vector<string> thisFilesLines;
440                         
441                         ifstream temp;
442                         m->openInputFile(outputNames[i], temp);
443                         
444                         //read through first line - labels
445                         m->getline(temp);                       
446                         m->gobble(temp);
447                         
448                         //for each label
449                         while (!temp.eof()) {
450                                 
451                                 string thisLine = "";
452                                 string tempLabel;
453                                 
454                                 for (int j = 0; j < 5; j++) {  
455                                         temp >> tempLabel; 
456                                         
457                                         //save for later
458                                         if (j == 1) { thisLine += groups[i] + "\t" + tempLabel + "\t";  }
459                                         else{  thisLine += tempLabel + "\t";    }
460                                 }
461                                 
462                                 thisLine += "\n";
463                                 
464                                 thisFilesLines.push_back(thisLine);
465                                 
466                                 m->gobble(temp);
467                         }
468                         
469                         files[outputNames[i]] = thisFilesLines;
470                         
471                         numLines = thisFilesLines.size();
472                         
473                         temp.close();
474                         m->mothurRemove(outputNames[i]);
475                 }
476                 
477                 //for each label
478                 for (int k = 0; k < numLines; k++) {
479                         
480                         //grab summary data for each group
481                         for (int i=0; i<outputNames.size(); i++) {
482                                 out << files[outputNames[i]][k];
483                         }
484                 }       
485                 
486                 
487                 out.close();
488                 
489                 //return combine file name
490                 return combineFileName;
491                 
492         }
493         catch(exception& e) {
494                 m->errorOut(e, "CatchAllCommand", "combineSummmary");
495                 exit(1);
496         }
497 }
498 //**********************************************************************************************************************
499 int CatchAllCommand::createSummaryFile(string file1, string label, ofstream& out) {
500         try {
501                 
502                 ifstream in;
503                 int able = m->openInputFile(file1, in, "noerror");
504                 
505                 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; }
506                         
507                 if (!in.eof()) {
508                         
509                         string header = m->getline(in); m->gobble(in);
510                         
511                         int pos = header.find("Total Number of Observed Species =");
512                         string numString = "";
513                         
514                         
515                         if (pos == string::npos) { m->mothurOut("[ERROR]: cannot parse " + file1); m->mothurOutEndLine(); }
516                         else {
517                                 //pos will be the position of the T in total, so we want to count to the position of =
518                                 pos += 34;
519                                 char c=header[pos];
520                                 while (c != ','){
521                                         if (c != ' ') {
522                                                 numString += c;
523                                         }
524                                         pos++;
525                                         c=header[pos];
526                                         
527                                         //sanity check
528                                         if (pos > header.length()) { m->mothurOut("Cannot find number of OTUs in " + file1); m->mothurOutEndLine(); in.close(); return 0; }
529                                 }
530                         }
531                                                                                                                           
532                         string firstline = m->getline(in); m->gobble(in);
533                         vector<string> values;
534                         m->splitAtComma(firstline, values);
535                         
536                         values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
537                         
538                         if (values.size() == 1) { //grab next line if firstline didn't have what you wanted
539                                 string secondline = m->getline(in); m->gobble(in);
540                                 values.clear();
541                                 m->splitAtComma(secondline, values);
542                                 
543                                 values.pop_back(); //last value is always a blank string since the last character in the line is always a ','
544                         }
545                         
546                         if (values.size() == 1) { //still not what we wanted fill values with numOTUs
547                                 values.resize(8, "");
548                                 values[1] = "Sobs";
549                                 values[4] = numString;
550                                 values[6] = numString;
551                                 values[7] = numString;
552                         }
553                         
554                         if (values.size() < 8) { values.resize(8, ""); }
555                         
556                         out << label << '\t' << values[1] << '\t' << values[4] << '\t' << values[6] << '\t' << values[7] << endl;
557                 }
558                 
559                 in.close();
560                 
561                 return 0;
562                 
563         }
564         catch(exception& e) {
565                 m->errorOut(e, "CatchAllCommand", "createSummaryFile");
566                 exit(1);
567         }
568 }
569 //**********************************************************************************************************************
570 vector<string> CatchAllCommand::parseSharedFile(string filename) {
571         try {
572                 vector<string> filenames;
573                 
574                 //read first line
575                 InputData* input = new InputData(filename, "sharedfile");
576                 vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
577                 
578                 string sharedFileRoot = outputDir + m->getRootName(m->getSimpleName(filename));
579                 
580                 //clears file before we start to write to it below
581                 for (int i=0; i<lookup.size(); i++) {
582                         m->mothurRemove((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
583                         filenames.push_back((sharedFileRoot + lookup[i]->getGroup() + ".sabund"));
584                         groups.push_back(lookup[i]->getGroup());
585                 }
586                 
587                 while(lookup[0] != NULL) {
588                         
589                         for (int i = 0; i < lookup.size(); i++) {
590                                 SAbundVector sav = lookup[i]->getSAbundVector();
591                                 ofstream out;
592                                 m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".sabund", out);
593                                 sav.print(out);
594                                 out.close();
595                         }
596                         
597                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
598                         lookup = input->getSharedRAbundVectors();
599                 }
600                 
601                 delete input;
602                 
603                 return filenames;
604         }
605         catch(exception& e) {
606                 m->errorOut(e, "CatchAllCommand", "parseSharedFile");
607                 exit(1);
608         }
609 }
610 /**************************************************************************************/