]> git.donarmstrong.com Git - mothur.git/blob - collectsharedcommand.cpp
fixed bug in sharedcommand and parselistcommand and changed file extension of sorenso...
[mothur.git] / collectsharedcommand.cpp
1 /*
2  *  collectsharedcommand.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 1/2/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "collectsharedcommand.h"
11 #include "sharedsobs.h"
12 #include "sharedchao1.h"
13 #include "sharedace.h"
14 #include "sharedjabund.h"
15 #include "sharedsorabund.h"
16 #include "sharedjclass.h"
17 #include "sharedsorclass.h"
18 #include "sharedjest.h"
19 #include "sharedsorest.h"
20 #include "sharedthetayc.h"
21 #include "sharedthetan.h"
22
23
24 //**********************************************************************************************************************
25
26 CollectSharedCommand::CollectSharedCommand(){
27         try {
28                 globaldata = GlobalData::getInstance();
29                 string fileNameRoot;
30                 fileNameRoot = getRootName(globaldata->inputFileName);
31                 groupmap = globaldata->gGroupmap;
32                 
33                 int i;
34                 for (i=0; i<globaldata->sharedEstimators.size(); i++) {
35                         if (globaldata->sharedEstimators[i] == "sharedChao") { 
36                                 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao", groupmap->namesOfGroups)));
37                         }else if (globaldata->sharedEstimators[i] == "sharedSobs") { 
38                                 cDisplays.push_back(new CollectDisplay(new SharedSobs(), new SharedOneColumnFile(fileNameRoot+"shared.sobs", groupmap->namesOfGroups)));
39                         }else if (globaldata->sharedEstimators[i] == "sharedAce") { 
40                                 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace", groupmap->namesOfGroups)));
41                         }else if (globaldata->sharedEstimators[i] == "sharedJabund") {  
42                                 cDisplays.push_back(new CollectDisplay(new SharedJAbund(), new SharedOneColumnFile(fileNameRoot+"shared.jabund", groupmap->namesOfGroups)));
43                         }else if (globaldata->sharedEstimators[i] == "sharedSorensonAbund") { 
44                                 cDisplays.push_back(new CollectDisplay(new SharedSorAbund(), new SharedOneColumnFile(fileNameRoot+"shared.sorabund", groupmap->namesOfGroups)));
45                         }else if (globaldata->sharedEstimators[i] == "sharedJclass") { 
46                                 cDisplays.push_back(new CollectDisplay(new SharedJclass(), new SharedOneColumnFile(fileNameRoot+"shared.jclass", groupmap->namesOfGroups)));
47                         }else if (globaldata->sharedEstimators[i] == "sharedSorClass") { 
48                                 cDisplays.push_back(new CollectDisplay(new SharedSorClass(), new SharedOneColumnFile(fileNameRoot+"shared.sorclass", groupmap->namesOfGroups)));
49                         }else if (globaldata->sharedEstimators[i] == "sharedJest") { 
50                                 cDisplays.push_back(new CollectDisplay(new SharedJest(), new SharedOneColumnFile(fileNameRoot+"shared.jest", groupmap->namesOfGroups)));
51                         }else if (globaldata->sharedEstimators[i] == "sharedSorEst") { 
52                                 cDisplays.push_back(new CollectDisplay(new SharedSorEst(), new SharedOneColumnFile(fileNameRoot+"shared.sorest", groupmap->namesOfGroups)));
53                         }else if (globaldata->sharedEstimators[i] == "SharedThetaYC") { 
54                                 cDisplays.push_back(new CollectDisplay(new SharedThetaYC(), new SharedOneColumnFile(fileNameRoot+"shared.thetayc", groupmap->namesOfGroups)));
55                         }else if (globaldata->sharedEstimators[i] == "SharedThetaN") { 
56                                 cDisplays.push_back(new CollectDisplay(new SharedThetaN(), new SharedOneColumnFile(fileNameRoot+"shared.thetan", groupmap->namesOfGroups)));
57                         }
58                 }
59         }
60         catch(exception& e) {
61                 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62                 exit(1);
63         }
64         catch(...) {
65                 cout << "An unknown error has occurred in the CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
66                 exit(1);
67         }       
68                         
69 }
70
71 //**********************************************************************************************************************
72
73 CollectSharedCommand::~CollectSharedCommand(){
74         delete order;
75         delete input;
76         delete cCurve;
77         delete read;
78 }
79
80 //**********************************************************************************************************************
81
82 int CollectSharedCommand::execute(){
83         try {
84                 int count = 1;
85                 read = new ReadPhilFile(globaldata->inputFileName);     
86                 read->read(&*globaldata); 
87                 
88                 input = globaldata->ginput;
89                 SharedList = globaldata->gSharedList;
90                 order = SharedList->getSharedOrderVector();
91                 
92                 while(order != NULL){
93                 
94                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
95                                 //create collectors curve
96                                 cCurve = new Collect(order, cDisplays);
97                                 convert(globaldata->getFreq(), freq);
98                                 cCurve->getSharedCurve(freq);
99                         
100                                 delete cCurve;
101                         
102                                 cout << order->getLabel() << '\t' << count << endl;
103                         }
104                         
105                         SharedList = input->getSharedListVector(); //get new list vector to process
106                         if (SharedList != NULL) {
107                                 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
108                                 count++;
109                         }else {
110                                 break;
111                         }
112                 
113                 }
114         
115                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
116                 return 0;
117         }
118         catch(exception& e) {
119                 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
120                 exit(1);
121         }
122         catch(...) {
123                 cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
124                 exit(1);
125         }       
126 }
127
128
129 //**********************************************************************************************************************