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