5 * Created by Sarah Westcott on 3/30/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "venncommand.h"
14 //#include "jackknife.h"
15 #include "sharedsobscollectsummary.h"
16 #include "sharedchao1.h"
17 #include "sharedace.h"
20 //**********************************************************************************************************************
22 VennCommand::VennCommand(){
24 globaldata = GlobalData::getInstance();
25 format = globaldata->getFormat();
26 validCalculator = new ValidCalculators();
30 if (format == "list") {
31 for (i=0; i<globaldata->Estimators.size(); i++) {
32 if (validCalculator->isValidCalculator("vennsingle", globaldata->Estimators[i]) == true) {
33 if (globaldata->Estimators[i] == "sobs") {
34 vennCalculators.push_back(new Sobs());
35 }else if (globaldata->Estimators[i] == "chao") {
36 vennCalculators.push_back(new Chao1());
37 }else if (globaldata->Estimators[i] == "ace") {
38 convert(globaldata->getAbund(), abund);
41 vennCalculators.push_back(new Ace(abund));
42 //}else if (globaldata->Estimators[i] == "jack") {
43 //vennCalculators.push_back(new Jackknife());
48 for (i=0; i<globaldata->Estimators.size(); i++) {
49 if (validCalculator->isValidCalculator("vennshared", globaldata->Estimators[i]) == true) {
50 if (globaldata->Estimators[i] == "sharedsobs") {
51 vennCalculators.push_back(new SharedSobsCS());
52 }else if (globaldata->Estimators[i] == "sharedchao") {
53 vennCalculators.push_back(new SharedChao1());
54 }else if (globaldata->Estimators[i] == "sharedace") {
55 vennCalculators.push_back(new SharedAce());
63 //reset calc for next command
64 globaldata->setCalc("");
69 cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function VennCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
73 cout << "An unknown error has occurred in the VennCommand class function VennCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
77 //**********************************************************************************************************************
79 VennCommand::~VennCommand(){
83 for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; }
86 //**********************************************************************************************************************
88 int VennCommand::execute(){
92 //if the users entered no valid calculators don't execute command
93 if (vennCalculators.size() == 0) { return 0; }
95 if (format == "sharedfile") {
97 read = new ReadOTUFile(globaldata->inputFileName);
98 read->read(&*globaldata);
100 input = globaldata->ginput;
101 lookup = input->getSharedRAbundVectors();
102 }else if (format == "list") {
103 //you are using just a list file and have only one group
104 read = new ReadOTUFile(globaldata->inputFileName);
105 read->read(&*globaldata);
107 sabund = globaldata->sabund;
108 input = globaldata->ginput;
112 if (format != "list") {
114 while(lookup[0] != NULL){
116 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
118 cout << lookup[0]->getLabel() << '\t' << count << endl;
120 if (lookup.size() > 4) {
121 cout << "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." << endl;
122 for (int i = lookup.size(); i > 3; i--) { delete lookup[i]; lookup.pop_back(); }
125 //util->getSharedVectors(globaldata->Groups, lookup, order); //fills group vectors from order vector.
126 venn->getPic(lookup, vennCalculators);
129 //prevent memory leak
130 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
132 //get next line to process
133 lookup = input->getSharedRAbundVectors();
137 //reset groups parameter
138 globaldata->Groups.clear();
142 while(sabund != NULL){
144 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(sabund->getLabel()) == 1){
146 cout << sabund->getLabel() << '\t' << count << endl;
147 venn->getPic(sabund, vennCalculators);
151 sabund = input->getSAbundVector();
156 globaldata->setGroups("");
159 catch(exception& e) {
160 cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
164 cout << "An unknown error has occurred in the VennCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
169 //**********************************************************************************************************************