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