]> git.donarmstrong.com Git - mothur.git/blob - venncommand.cpp
added [ERROR] flag if command aborts
[mothur.git] / venncommand.cpp
1 /*
2  *  venncommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 3/30/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "venncommand.h"
11 #include "ace.h"
12 #include "sobs.h"
13 #include "chao1.h"
14 //#include "jackknife.h"
15 #include "sharedsobscollectsummary.h"
16 #include "sharedchao1.h"
17 #include "sharedace.h"
18 #include "nseqs.h"
19
20
21 //**********************************************************************************************************************
22 vector<string> VennCommand::getValidParameters(){       
23         try {
24                 string Array[] =  {"groups","label","calc","permute", "abund","nseqs","outputdir","inputdir"};
25                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
26                 return myArray;
27         }
28         catch(exception& e) {
29                 m->errorOut(e, "VennCommand", "getValidParameters");
30                 exit(1);
31         }
32 }
33 //**********************************************************************************************************************
34 VennCommand::VennCommand(){     
35         try {
36                 abort = true; calledHelp = true; 
37                 vector<string> tempOutNames;
38                 outputTypes["svg"] = tempOutNames;
39         }
40         catch(exception& e) {
41                 m->errorOut(e, "VennCommand", "VennCommand");
42                 exit(1);
43         }
44 }
45 //**********************************************************************************************************************
46 vector<string> VennCommand::getRequiredParameters(){    
47         try {
48                 vector<string> myArray;
49                 return myArray;
50         }
51         catch(exception& e) {
52                 m->errorOut(e, "VennCommand", "getRequiredParameters");
53                 exit(1);
54         }
55 }
56 //**********************************************************************************************************************
57 vector<string> VennCommand::getRequiredFiles(){ 
58         try {
59                 string Array[] =  {"list","shared","or"};
60                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
61                 return myArray;
62         }
63         catch(exception& e) {
64                 m->errorOut(e, "VennCommand", "getRequiredFiles");
65                 exit(1);
66         }
67 }
68 //**********************************************************************************************************************
69
70 VennCommand::VennCommand(string option)  {
71         try {
72                 globaldata = GlobalData::getInstance();
73                 abort = false; calledHelp = false;   
74                 allLines = 1;
75                 labels.clear();
76                         
77                 //allow user to run help
78                 if(option == "help") { help(); abort = true; calledHelp = true; }
79                 
80                 else {
81                         //valid paramters for this command
82                         string AlignArray[] =  {"groups","label","calc","permute", "abund","nseqs","outputdir","inputdir"};
83                         vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
84                         
85                         OptionParser parser(option);
86                         map<string,string> parameters = parser.getParameters();
87                         
88                         ValidParameters validParameter;
89                         
90                         //check to make sure all parameters are valid for command
91                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
92                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
93                         }
94                         
95                         //make sure the user has already run the read.otu command
96                         if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) {
97                                 m->mothurOut("You must read a list, or a list and a group, or a shared before you can use the venn command."); m->mothurOutEndLine(); abort = true; 
98                         }
99                         
100                         //if the user changes the output directory command factory will send this info to us in the output parameter 
101                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
102                                 outputDir = ""; 
103                                 outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it       
104                         }
105
106                         //check for optional parameter and set defaults
107                         // ...at some point should added some additional type checking...
108                         label = validParameter.validFile(parameters, "label", false);                   
109                         if (label == "not found") { label = ""; }
110                         else { 
111                                 if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
112                                 else { allLines = 1;  }
113                         }
114                         
115                         //if the user has not specified any labels use the ones from read.otu
116                         if (label == "") {  
117                                 allLines = globaldata->allLines; 
118                                 labels = globaldata->labels; 
119                         }
120                         
121                         groups = validParameter.validFile(parameters, "groups", false);                 
122                         if (groups == "not found") { groups = ""; }
123                         else { 
124                                 m->splitAtDash(groups, Groups);
125                                 globaldata->Groups = Groups;
126                         }
127                         
128                         format = globaldata->getFormat();
129                         calc = validParameter.validFile(parameters, "calc", false);                     
130                         if (calc == "not found") { 
131                                 if(format == "list") { calc = "sobs"; }
132                                 else { calc = "sharedsobs"; }
133                         }
134                         else { 
135                                  if (calc == "default")  {  
136                                         if(format == "list") { calc = "sobs"; }
137                                         else { calc = "sharedsobs"; }
138                                 }
139                         }
140                         m->splitAtDash(calc, Estimators);
141                         
142                         string temp;
143                         temp = validParameter.validFile(parameters, "abund", false);            if (temp == "not found") { temp = "10"; }
144                         convert(temp, abund); 
145                         
146                         temp = validParameter.validFile(parameters, "nseqs", false);            if (temp == "not found"){       temp = "f";                             }
147                         nseqs = m->isTrue(temp); 
148
149                         temp = validParameter.validFile(parameters, "permute", false);                  if (temp == "not found"){       temp = "f";                             }
150                         perm = m->isTrue(temp); 
151
152                         if (abort == false) {
153                                 validCalculator = new ValidCalculators();
154                 
155                                 int i;
156                                 
157                                 if (format == "list") {
158                                         for (i=0; i<Estimators.size(); i++) {
159                                                 if (validCalculator->isValidCalculator("vennsingle", Estimators[i]) == true) { 
160                                                         if (Estimators[i] == "sobs") { 
161                                                                 vennCalculators.push_back(new Sobs());
162                                                         }else if (Estimators[i] == "chao") { 
163                                                                 vennCalculators.push_back(new Chao1());
164                                                         }else if (Estimators[i] == "ace") {
165                                                                 if(abund < 5)
166                                                                         abund = 10;
167                                                                 vennCalculators.push_back(new Ace(abund));
168                                                         }
169                                                 }
170                                         }
171                                 }else {
172                                         for (i=0; i<Estimators.size(); i++) {
173                                                 if (validCalculator->isValidCalculator("vennshared", Estimators[i]) == true) { 
174                                                         if (Estimators[i] == "sharedsobs") { 
175                                                                 vennCalculators.push_back(new SharedSobsCS());
176                                                         }else if (Estimators[i] == "sharedchao") { 
177                                                                 vennCalculators.push_back(new SharedChao1());
178                                                         }else if (Estimators[i] == "sharedace") { 
179                                                                 vennCalculators.push_back(new SharedAce());
180                                                         }
181                                                 }
182                                         }
183                                 }
184                                 
185                                 //if the users entered no valid calculators don't execute command
186                                 if (vennCalculators.size() == 0) { m->mothurOut("No valid calculators given, please correct."); m->mothurOutEndLine(); abort = true;  }
187                                 else {  venn = new Venn(outputDir, nseqs);  }
188                         }
189                         
190                 }
191
192                 
193                                 
194         }
195         catch(exception& e) {
196                 m->errorOut(e, "VennCommand", "VennCommand");
197                 exit(1);
198         }
199 }
200
201 //**********************************************************************************************************************
202
203 void VennCommand::help(){
204         try {
205                 m->mothurOut("The venn command can only be executed after a successful read.otu command.\n");
206                 m->mothurOut("The venn command parameters are groups, calc, abund, nseqs, permute and label.  No parameters are required.\n");
207                 m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included in your venn diagram, you may only use a maximum of 4 groups.\n");
208                 m->mothurOut("The group names are separated by dashes. The label allows you to select what distance levels you would like a venn diagram created for, and are also separated by dashes.\n");
209                 m->mothurOut("The venn command should be in the following format: venn(groups=yourGroups, calc=yourCalcs, label=yourLabels, abund=yourAbund).\n");
210                 m->mothurOut("Example venn(groups=A-B-C, calc=sharedsobs-sharedchao, abund=20).\n");
211                 m->mothurOut("The default value for groups is all the groups in your groupfile up to 4, and all labels in your inputfile will be used.\n");
212                 m->mothurOut("The default value for calc is sobs if you have only read a list file or if you have selected only one group, and sharedsobs if you have multiple groups.\n");
213                 m->mothurOut("The default available estimators for calc are sobs, chao and ace if you have only read a list file, and sharedsobs, sharedchao and sharedace if you have read a list and group file or a shared file.\n");
214                 m->mothurOut("The nseqs parameter will output the number of sequences represented by the otus in the picture, default=F.\n");
215                 m->mothurOut("If you have more than 4 groups, the permute parameter will find all possible combos of 4 of your groups and create pictures for them, default=F.\n");
216                 m->mothurOut("The only estimators available four 4 groups are sharedsobs and sharedchao.\n");
217                 m->mothurOut("The venn command outputs a .svg file for each calculator you specify at each distance you choose.\n");
218                 m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n");
219         }
220         catch(exception& e) {
221                 m->errorOut(e, "VennCommand", "help");
222                 exit(1);
223         }
224 }
225
226
227 //**********************************************************************************************************************
228
229 VennCommand::~VennCommand(){
230         if (abort == false) {
231                 delete input; globaldata->ginput = NULL;
232                 delete read;
233                 delete venn;
234                 globaldata->sabund = NULL;
235                 delete validCalculator;
236         }
237         
238 }
239
240 //**********************************************************************************************************************
241
242 int VennCommand::execute(){
243         try {
244         
245                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
246                 
247                 string lastLabel;
248                 
249                 if (format == "sharedfile") {
250                         //you have groups
251                         read = new ReadOTUFile(globaldata->inputFileName);      
252                         read->read(&*globaldata); 
253                         
254                         input = globaldata->ginput;
255                         lookup = input->getSharedRAbundVectors();
256                         lastLabel = lookup[0]->getLabel();
257                         
258                         if ((lookup.size() > 4) && (perm)) { combosOfFour = findCombinations(lookup.size()); }
259                 }else if (format == "list") {
260                         //you are using just a list file and have only one group
261                         read = new ReadOTUFile(globaldata->inputFileName);      
262                         read->read(&*globaldata); 
263                 
264                         sabund = globaldata->sabund;
265                         lastLabel = sabund->getLabel();
266                         input = globaldata->ginput;
267                 }
268                 
269                 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
270                 set<string> processedLabels;
271                 set<string> userLabels = labels;
272
273                 if (format != "list") { 
274                         
275                         //as long as you are not at the end of the file or done wih the lines you want
276                         while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
277                         
278                                 if (m->control_pressed) {
279                                         for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
280                                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
281                                         globaldata->Groups.clear(); 
282                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
283                                         return 0;
284                                 }
285
286                                 if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
287                                         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
288                                         processedLabels.insert(lookup[0]->getLabel());
289                                         userLabels.erase(lookup[0]->getLabel());
290                                         
291                                         if ((lookup.size() > 4) && (!perm)){
292                                                 m->mothurOut("Error: Too many groups chosen.  You may use up to 4 groups with the venn command.  I will use the first four groups in your groupfile. If you set perm=t, I will find all possible combos of 4 groups."); m->mothurOutEndLine();
293                                                 for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor
294                                         
295                                                 vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
296                                                 for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]);  } }
297
298                                         }else if ((lookup.size() > 4) && (perm)) {
299                                                 set< set<int> >::iterator it3;
300                                                 set<int>::iterator it2;
301                                                 for (it3 = combosOfFour.begin(); it3 != combosOfFour.end(); it3++) {  
302                         
303                                                         set<int> poss = *it3;
304                                                         vector<SharedRAbundVector*> subset;
305                                                         for (it2 = poss.begin(); it2 != poss.end(); it2++) {   subset.push_back(lookup[*it2]);   }
306                                                         
307                                                         vector<string> outfilenames = venn->getPic(subset, vennCalculators);
308                                                         for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]); }  }
309                                                 }               
310                                         }else {
311                                                 vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
312                                                 for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]);  }  }
313                                         }                                       
314                                 }
315                                 
316                                 if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
317                                         string saveLabel = lookup[0]->getLabel();
318                                         
319                                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
320                                         lookup = input->getSharedRAbundVectors(lastLabel);
321
322                                         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
323                                         processedLabels.insert(lookup[0]->getLabel());
324                                         userLabels.erase(lookup[0]->getLabel());
325
326                                         if ((lookup.size() > 4) && (!perm)){
327                                                 m->mothurOut("Error: Too many groups chosen.  You may use up to 4 groups with the venn command.  I will use the first four groups in your groupfile. If you set perm=t, I will find all possible combos of 4 groups."); m->mothurOutEndLine();
328                                                 for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor
329                                         
330                                                 vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
331                                                 for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]);  }  }
332
333                                         }else if ((lookup.size() > 4) && (perm)) {
334                                                 set< set<int> >::iterator it3;
335                                                 set<int>::iterator it2;
336                                                 for (it3 = combosOfFour.begin(); it3 != combosOfFour.end(); it3++) {  
337                         
338                                                         set<int> poss = *it3;
339                                                         vector<SharedRAbundVector*> subset;
340                                                         for (it2 = poss.begin(); it2 != poss.end(); it2++) {   subset.push_back(lookup[*it2]);   }
341                                                         
342                                                         vector<string> outfilenames = venn->getPic(subset, vennCalculators);
343                                                         for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]);  }  }
344                                                 }               
345                                         }else {
346                                                 vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
347                                                 for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]);  }  }
348                                         }
349                                                                                 
350                                         //restore real lastlabel to save below
351                                         lookup[0]->setLabel(saveLabel);
352                                 }
353                                 
354                                 
355                                 lastLabel = lookup[0]->getLabel();      
356                                                 
357                                 //get next line to process
358                                 for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
359                                 lookup = input->getSharedRAbundVectors();
360                         }
361                         
362                         if (m->control_pressed) {
363                                         for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
364                                         globaldata->Groups.clear(); 
365                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
366                                         return 0;
367                         }
368
369                         
370                         //output error messages about any remaining user labels
371                         set<string>::iterator it;
372                         bool needToRun = false;
373                         for (it = userLabels.begin(); it != userLabels.end(); it++) {  
374                                 m->mothurOut("Your file does not include the label " + *it); 
375                                 if (processedLabels.count(lastLabel) != 1) {
376                                         m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
377                                         needToRun = true;
378                                 }else {
379                                         m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
380                                 }
381                         }
382                 
383                         //run last label if you need to
384                         if (needToRun == true)  {
385                                         for (int i = 0; i < lookup.size(); i++) {  if (lookup[i] != NULL) {     delete lookup[i]; }  } 
386                                         lookup = input->getSharedRAbundVectors(lastLabel);
387
388                                         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
389                                         processedLabels.insert(lookup[0]->getLabel());
390                                         userLabels.erase(lookup[0]->getLabel());
391
392                                         if ((lookup.size() > 4) && (!perm)){
393                                                 m->mothurOut("Error: Too many groups chosen.  You may use up to 4 groups with the venn command.  I will use the first four groups in your groupfile. If you set perm=t, I will find all possible combos of 4 groups."); m->mothurOutEndLine();
394                                                 for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor
395                                         
396                                                 vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
397                                                 for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]); }  }
398
399                                         }else if ((lookup.size() > 4) && (perm)) {
400                                                 set< set<int> >::iterator it3;
401                                                 set<int>::iterator it2;
402                                                 for (it3 = combosOfFour.begin(); it3 != combosOfFour.end(); it3++) {  
403                         
404                                                         set<int> poss = *it3;
405                                                         vector<SharedRAbundVector*> subset;
406                                                         for (it2 = poss.begin(); it2 != poss.end(); it2++) {   subset.push_back(lookup[*it2]);   }
407                                                         
408                                                         vector<string> outfilenames = venn->getPic(subset, vennCalculators);
409                                                         for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]); }  }
410                                                 }               
411                                         }else {
412                                                 vector<string> outfilenames = venn->getPic(lookup, vennCalculators);
413                                                 for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]);  }  }
414                                         }
415                                         
416                                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
417                         }
418                 
419
420                         //reset groups parameter
421                         globaldata->Groups.clear();  
422                         
423                         if (m->control_pressed) {
424                                         for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
425                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
426                                         return 0;
427                         }
428
429                         
430                 }else{
431                 
432                         while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
433                         
434                                 if (m->control_pressed) {
435                                         for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
436                                         delete sabund;
437                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
438                                         return 0;
439                                 }
440                 
441                                 if(allLines == 1 || labels.count(sabund->getLabel()) == 1){                     
442         
443                                         m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
444                                         vector<string> outfilenames = venn->getPic(sabund, vennCalculators);
445                                         for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]);  }  }
446
447                                         
448                                         processedLabels.insert(sabund->getLabel());
449                                         userLabels.erase(sabund->getLabel());
450                                 }
451                                 
452                                 if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
453                                         string saveLabel = sabund->getLabel();
454                                 
455                                         delete sabund;
456                                         sabund = input->getSAbundVector(lastLabel);
457                                         
458                                         m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
459                                         vector<string> outfilenames = venn->getPic(sabund, vennCalculators);
460                                         for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]);  }  }
461
462                                         
463                                         processedLabels.insert(sabund->getLabel());
464                                         userLabels.erase(sabund->getLabel());
465                                         
466                                         //restore real lastlabel to save below
467                                         sabund->setLabel(saveLabel);
468                                 }               
469                                 
470                                 lastLabel = sabund->getLabel();         
471                                 
472                                 delete sabund;
473                                 sabund = input->getSAbundVector();
474                         }
475                         
476                         if (m->control_pressed) {
477                                         for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
478                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
479                                         return 0;
480                         }
481                         
482                         //output error messages about any remaining user labels
483                         set<string>::iterator it;
484                         bool needToRun = false;
485                         for (it = userLabels.begin(); it != userLabels.end(); it++) {  
486                                 m->mothurOut("Your file does not include the label " + *it); 
487                                 if (processedLabels.count(lastLabel) != 1) {
488                                         m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
489                                         needToRun = true;
490                                 }else {
491                                         m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
492                                 }
493                         }
494                 
495                         //run last label if you need to
496                         if (needToRun == true)  {
497                                 if (sabund != NULL) {   delete sabund;  }
498                                 sabund = input->getSAbundVector(lastLabel);
499                                         
500                                 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
501                                 vector<string> outfilenames = venn->getPic(sabund, vennCalculators);
502                                 for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]);  }  }
503
504                                 delete sabund;
505                                         
506                         }
507                         
508                         if (m->control_pressed) {
509                                         for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
510                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
511                                         return 0;
512                         }
513                 }
514                 
515                 for (int i = 0; i < vennCalculators.size(); i++) {      delete vennCalculators[i];      }
516                 
517                 m->mothurOutEndLine();
518                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
519                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
520                 m->mothurOutEndLine();
521
522                 
523                 return 0;
524         }
525         catch(exception& e) {
526                 m->errorOut(e, "VennCommand", "execute");
527                 exit(1);
528         }
529 }
530 //**********************************************************************************************************************
531 //returns a vector of sets containing the 4 group combinations
532 set< set<int> > VennCommand::findCombinations(int lookupSize){
533         try {
534                 set< set<int> > combos;
535                 
536                 set<int> possibles;
537                 for (int i = 0; i < lookupSize; i++) {  possibles.insert(i);  }
538                 
539                 getCombos(possibles, combos);
540                 
541                 return combos;
542                 
543         }
544         catch(exception& e) {
545                 m->errorOut(e, "VennCommand", "findCombinations");
546                 exit(1);
547         }
548 }
549 //**********************************************************************************************************************
550 //recusively finds combos of 4
551 int VennCommand::getCombos(set<int> possibles, set< set<int> >& combos){
552         try {
553                 
554                 if (possibles.size() == 4) { //done
555                         if (combos.count(possibles) == 0) { //no dups
556                                 combos.insert(possibles);
557                         }
558                 }else { //we still have work to do
559                         set<int>::iterator it;
560                         set<int>::iterator it2;
561                         for (it = possibles.begin(); it != possibles.end(); it++) {  
562                                 
563                                 set<int> newPossibles;
564                                 for (it2 = possibles.begin(); it2 != possibles.end(); it2++) {  //all possible combos of one length smaller
565                                         if (*it != *it2) { 
566                                                 newPossibles.insert(*it2);
567                                         }
568                                 }
569                                 getCombos(newPossibles, combos);
570                         }
571                 }
572                 
573                 return 0;
574         }
575         catch(exception& e) {
576                 m->errorOut(e, "VennCommand", "getCombos");
577                 exit(1);
578         }
579 }
580
581 //**********************************************************************************************************************