]> git.donarmstrong.com Git - mothur.git/blob - rarefactsharedcommand.cpp
added read.shared, broke up globaldata a bit
[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
13 //**********************************************************************************************************************
14
15 RareFactSharedCommand::RareFactSharedCommand(){
16         try {
17                 globaldata = GlobalData::getInstance();
18                 string fileNameRoot;
19                 fileNameRoot = getRootName(globaldata->inputFileName);
20                 format = globaldata->getFormat();
21                 validCalculator = new ValidCalculators();
22                                 
23                 int i;
24                 for (i=0; i<globaldata->Estimators.size(); i++) {
25                         if (validCalculator->isValidCalculator("sharedrarefaction", globaldata->Estimators[i]) == true) { 
26                                 if (globaldata->Estimators[i] == "sharedobserved") { 
27                                         rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", "")));
28                                 }
29                         }
30                 }
31                 
32                 //reset calc for next command
33                 globaldata->setCalc("");
34
35         }
36         catch(exception& e) {
37                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
38                 exit(1);
39         }
40         catch(...) {
41                 cout << "An unknown error has occurred in the RareFactSharedCommand class function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
42                 exit(1);
43         }       
44                         
45 }
46
47 //**********************************************************************************************************************
48
49 RareFactSharedCommand::~RareFactSharedCommand(){
50         delete order;
51         delete input;
52         delete rCurve;
53         delete read;
54 }
55
56 //**********************************************************************************************************************
57
58 int RareFactSharedCommand::execute(){
59         try {
60                 int count = 1;
61                 
62                 //if the users entered no valid calculators don't execute command
63                 if (rDisplays.size() == 0) { return 0; }
64
65                 if (format == "sharedfile") {
66                         read = new ReadPhilFile(globaldata->inputFileName);     
67                         read->read(&*globaldata); 
68                         
69                         input = globaldata->ginput;
70                         order = input->getSharedOrderVector();
71                 }else {
72                         //you are using a list and a groupfile
73                         read = new ReadPhilFile(globaldata->inputFileName);     
74                         read->read(&*globaldata); 
75                 
76                         input = globaldata->ginput;
77                         SharedList = globaldata->gSharedList;
78                         order = SharedList->getSharedOrderVector();
79                 }
80                 
81                 while(order != NULL){
82                 
83                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
84                                 //create collectors curve
85                                 rCurve = new Rarefact(order, rDisplays);
86                                 convert(globaldata->getFreq(), freq);
87                                 convert(globaldata->getIters(), nIters);
88                                 rCurve->getSharedCurve(freq, nIters);
89                         
90                                 delete rCurve;
91                         
92                                 cout << order->getLabel() << '\t' << count << endl;
93                         }
94                         
95                         //get next line to process
96                         if (format == "sharedfile") {
97                                 order = input->getSharedOrderVector();
98                         }else {
99                                 //you are using a list and a groupfile
100                                 SharedList = input->getSharedListVector(); //get new list vector to process
101                                 if (SharedList != NULL) {
102                                         order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
103                                 }else {
104                                         break;
105                                 }
106                         }
107                         
108                         count++;
109                 }
110         
111                 for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
112                 return 0;
113         }
114         catch(exception& e) {
115                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
116                 exit(1);
117         }
118         catch(...) {
119                 cout << "An unknown error has occurred in the RareFactSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
120                 exit(1);
121         }       
122 }
123
124
125 //**********************************************************************************************************************