]> git.donarmstrong.com Git - mothur.git/blob - venncommand.cpp
started shared utilities, updates to venn and heatmap added tree.groups command
[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
19
20 //**********************************************************************************************************************
21
22 VennCommand::VennCommand(){
23         try {
24                 globaldata = GlobalData::getInstance();
25                 format = globaldata->getFormat();
26                 validCalculator = new ValidCalculators();
27                 util = new SharedUtil();
28                 
29                 int i;
30                 
31                 if (format == "list") {
32                         for (i=0; i<globaldata->Estimators.size(); i++) {
33                                 if (validCalculator->isValidCalculator("vennsingle", globaldata->Estimators[i]) == true) { 
34                                         if (globaldata->Estimators[i] == "sobs") { 
35                                                 vennCalculators.push_back(new Sobs());
36                                         }else if (globaldata->Estimators[i] == "chao") { 
37                                                 vennCalculators.push_back(new Chao1());
38                                         }else if (globaldata->Estimators[i] == "ace") {
39                                                 convert(globaldata->getAbund(), abund);
40                                                 if(abund < 5)
41                                                         abund = 10;
42                                                 vennCalculators.push_back(new Ace(abund));
43                                         //}else if (globaldata->Estimators[i] == "jack") {      
44                                                 //vennCalculators.push_back(new Jackknife());
45                                         }
46                                 }
47                         }
48                 }else {
49                         for (i=0; i<globaldata->Estimators.size(); i++) {
50                                 if (validCalculator->isValidCalculator("vennshared", globaldata->Estimators[i]) == true) { 
51                                         if (globaldata->Estimators[i] == "sharedsobs") { 
52                                                 vennCalculators.push_back(new SharedSobsCS());
53                                         }else if (globaldata->Estimators[i] == "sharedchao") { 
54                                                 vennCalculators.push_back(new SharedChao1());
55                                         }else if (globaldata->Estimators[i] == "sharedace") { 
56                                                 vennCalculators.push_back(new SharedAce());
57                                         }
58                                 }
59                         }
60                 }
61                 
62                 venn = new Venn();
63                 
64                 //reset calc for next command
65                 globaldata->setCalc("");
66
67                 
68         }
69         catch(exception& e) {
70                 cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function VennCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
71                 exit(1);
72         }
73         catch(...) {
74                 cout << "An unknown error has occurred in the VennCommand class function VennCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
75                 exit(1);
76         }       
77 }
78 //**********************************************************************************************************************
79
80 VennCommand::~VennCommand(){
81         delete input;
82         delete read;
83         delete venn;
84         delete util;
85 }
86
87 //**********************************************************************************************************************
88
89 int VennCommand::execute(){
90         try {
91                 int count = 1;  
92                 
93                 //if the users entered no valid calculators don't execute command
94                 if (vennCalculators.size() == 0) { return 0; }
95                 
96                 if (format == "sharedfile") {
97                         //you have groups
98                         read = new ReadPhilFile(globaldata->inputFileName);     
99                         read->read(&*globaldata); 
100                         
101                         input = globaldata->ginput;
102                         order = input->getSharedOrderVector();
103                 }else if (format == "shared") {
104                         //you are using a list and a groupfile
105                         read = new ReadPhilFile(globaldata->inputFileName);     
106                         read->read(&*globaldata); 
107                 
108                         input = globaldata->ginput;
109                         SharedList = globaldata->gSharedList;
110                         order = SharedList->getSharedOrderVector();
111                 }else if (format == "list") {
112                         //you are using just a list file and have only one group
113                         read = new ReadPhilFile(globaldata->inputFileName);     
114                         read->read(&*globaldata); 
115                 
116                         ordersingle = globaldata->gorder;
117                         input = globaldata->ginput;
118                 }
119
120                 
121                 if (format != "list") { 
122                         
123                         util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "venn");
124                         globaldata->setGroups("");
125                         
126                         while(order != NULL){
127                 
128                                 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
129         
130                                         cout << order->getLabel() << '\t' << count << endl;
131                                         venn->getPic(order, vennCalculators);
132
133                                 }
134                                                 
135                                 //get next line to process
136                                 if (format == "sharedfile") {
137                                         order = input->getSharedOrderVector();
138                                 }else {
139                                         //you are using a list and a groupfile
140                                         SharedList = input->getSharedListVector(); //get new list vector to process
141                                         if (SharedList != NULL) {
142                                                 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
143                                         }else {
144                                                 break;
145                                         }
146                                 }
147                                 count++;
148                         }
149                         
150                         //reset groups parameter
151                         globaldata->Groups.clear();  
152                         
153                 }else{
154                         while(ordersingle != NULL){
155                 
156                                 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(ordersingle->getLabel()) == 1){                 
157         
158                                         cout << ordersingle->getLabel() << '\t' << count << endl;
159                                         venn->getPic(ordersingle, vennCalculators);
160                                         
161                                 }
162                                 
163                                 ordersingle = (input->getOrderVector());
164                                 count++;
165                         }
166                 }
167                 
168                 return 0;
169         }
170         catch(exception& e) {
171                 cout << "Standard Error: " << e.what() << " has occurred in the VennCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
172                 exit(1);
173         }
174         catch(...) {
175                 cout << "An unknown error has occurred in the VennCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
176                 exit(1);
177         }               
178 }
179
180 //**********************************************************************************************************************
181