]> git.donarmstrong.com Git - mothur.git/blob - rarefactsharedcommand.cpp
started shared utilities, updates to venn and heatmap added tree.groups command
[mothur.git] / rarefactsharedcommand.cpp
1 /*
2  *  rarefactsharedcommand.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 1/6/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "rarefactsharedcommand.h"
11 #include "sharedsobs.h"
12 #include "sharednseqs.h"
13
14 //**********************************************************************************************************************
15
16 RareFactSharedCommand::RareFactSharedCommand(){
17         try {
18                 globaldata = GlobalData::getInstance();
19                 string fileNameRoot;
20                 fileNameRoot = getRootName(globaldata->inputFileName);
21                 format = globaldata->getFormat();
22                 validCalculator = new ValidCalculators();
23                 util = new SharedUtil();
24                                 
25                 int i;
26                 for (i=0; i<globaldata->Estimators.size(); i++) {
27                         if (validCalculator->isValidCalculator("sharedrarefaction", globaldata->Estimators[i]) == true) { 
28                                 if (globaldata->Estimators[i] == "sharedobserved") { 
29                                         rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", "")));
30                                 }else if (globaldata->Estimators[i] == "sharednseqs") { 
31                                         rDisplays.push_back(new RareDisplay(new SharedNSeqs(), new SharedThreeColumnFile(fileNameRoot+"shared.r_nseqs", "")));
32                                 }
33
34                         }
35                 }
36                 
37                 //reset calc for next command
38                 globaldata->setCalc("");
39
40         }
41         catch(exception& e) {
42                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
43                 exit(1);
44         }
45         catch(...) {
46                 cout << "An unknown error has occurred in the RareFactSharedCommand class function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
47                 exit(1);
48         }       
49                         
50 }
51
52 //**********************************************************************************************************************
53
54 RareFactSharedCommand::~RareFactSharedCommand(){
55         delete order;
56         delete input;
57         delete rCurve;
58         delete read;
59         delete util;
60 }
61
62 //**********************************************************************************************************************
63
64 int RareFactSharedCommand::execute(){
65         try {
66                 int count = 1;
67                 
68                 //if the users entered no valid calculators don't execute command
69                 if (rDisplays.size() == 0) { return 0; }
70
71                 if (format == "sharedfile") {
72                         read = new ReadPhilFile(globaldata->inputFileName);     
73                         read->read(&*globaldata); 
74                         
75                         input = globaldata->ginput;
76                         order = input->getSharedOrderVector();
77                 }else {
78                         //you are using a list and a groupfile
79                         read = new ReadPhilFile(globaldata->inputFileName);     
80                         read->read(&*globaldata); 
81                 
82                         input = globaldata->ginput;
83                         SharedList = globaldata->gSharedList;
84                         order = SharedList->getSharedOrderVector();
85                 }
86                 
87                 //set users groups
88                 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "rarefact");
89                 
90                 while(order != NULL){
91                 
92                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
93                                 //create collectors curve
94                                 rCurve = new Rarefact(order, rDisplays);
95                                 convert(globaldata->getFreq(), freq);
96                                 convert(globaldata->getIters(), nIters);
97                                 rCurve->getSharedCurve(freq, nIters);
98                         
99                                 delete rCurve;
100                         
101                                 cout << order->getLabel() << '\t' << count << endl;
102                         }
103                         
104                         //get next line to process
105                         if (format == "sharedfile") {
106                                 order = input->getSharedOrderVector();
107                         }else {
108                                 //you are using a list and a groupfile
109                                 SharedList = input->getSharedListVector(); //get new list vector to process
110                                 if (SharedList != NULL) {
111                                         order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
112                                 }else {
113                                         break;
114                                 }
115                         }
116                         
117                         count++;
118                 }
119         
120                 for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
121                 
122                 //reset groups parameter
123                 globaldata->Groups.clear();  globaldata->setGroups("");
124
125                 return 0;
126         }
127         catch(exception& e) {
128                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
129                 exit(1);
130         }
131         catch(...) {
132                 cout << "An unknown error has occurred in the RareFactSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
133                 exit(1);
134         }       
135 }
136
137
138 //**********************************************************************************************************************