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