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