2 * collectsharedcommand.cpp
5 * Created by Sarah Westcott on 1/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "collectsharedcommand.h"
11 #include "sharedsobscollectsummary.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 <<<<<<< collectsharedcommand.cpp
23 #include "sharedkstest.h"
24 #include "sharedbdiversity.h"
26 #include "sharednseqs.h"
27 #include "sharedochiai.h"
28 #include "sharedanderberg.h"
29 #include "sharedkulczynski.h"
30 #include "sharedkulczynskicody.h"
31 #include "sharedlennon.h"
32 #include "sharedmorisitahorn.h"
33 #include "sharedbraycurtis.h"
37 //**********************************************************************************************************************
39 CollectSharedCommand::CollectSharedCommand(){
41 globaldata = GlobalData::getInstance();
43 fileNameRoot = getRootName(globaldata->inputFileName);
44 format = globaldata->getFormat();
45 validCalculator = new ValidCalculators();
48 for (i=0; i<globaldata->Estimators.size(); i++) {
49 if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) {
50 if (globaldata->Estimators[i] == "sharedchao") {
51 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
52 }else if (globaldata->Estimators[i] == "sharedsobs") {
53 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
54 }else if (globaldata->Estimators[i] == "sharedace") {
55 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
56 }else if (globaldata->Estimators[i] == "sharedjabund") {
57 cDisplays.push_back(new CollectDisplay(new SharedJAbund(), new SharedOneColumnFile(fileNameRoot+"shared.jabund")));
58 }else if (globaldata->Estimators[i] == "sharedsorensonabund") {
59 cDisplays.push_back(new CollectDisplay(new SharedSorAbund(), new SharedOneColumnFile(fileNameRoot+"shared.sorabund")));
60 }else if (globaldata->Estimators[i] == "sharedjclass") {
61 cDisplays.push_back(new CollectDisplay(new SharedJclass(), new SharedOneColumnFile(fileNameRoot+"shared.jclass")));
62 }else if (globaldata->Estimators[i] == "sharedsorclass") {
63 cDisplays.push_back(new CollectDisplay(new SharedSorClass(), new SharedOneColumnFile(fileNameRoot+"shared.sorclass")));
64 }else if (globaldata->Estimators[i] == "sharedjest") {
65 cDisplays.push_back(new CollectDisplay(new SharedJest(), new SharedOneColumnFile(fileNameRoot+"shared.jest")));
66 }else if (globaldata->Estimators[i] == "sharedsorest") {
67 cDisplays.push_back(new CollectDisplay(new SharedSorEst(), new SharedOneColumnFile(fileNameRoot+"shared.sorest")));
68 }else if (globaldata->Estimators[i] == "sharedthetayc") {
69 cDisplays.push_back(new CollectDisplay(new SharedThetaYC(), new SharedOneColumnFile(fileNameRoot+"shared.thetayc")));
70 }else if (globaldata->Estimators[i] == "sharedthetan") {
71 cDisplays.push_back(new CollectDisplay(new SharedThetaN(), new SharedOneColumnFile(fileNameRoot+"shared.thetan")));
72 }else if (globaldata->Estimators[i] == "sharedkstest") {
73 cDisplays.push_back(new CollectDisplay(new SharedKSTest(), new SharedOneColumnFile(fileNameRoot+"shared.kstest")));
74 }else if (globaldata->Estimators[i] == "sharedbdiversity") {
75 cDisplays.push_back(new CollectDisplay(new SharedBDiversity(), new SharedOneColumnFile(fileNameRoot+"shared.bdiversity")));
76 }else if (globaldata->Estimators[i] == "sharednseqs") {
77 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
78 }else if (globaldata->Estimators[i] == "sharedochiai") {
79 cDisplays.push_back(new CollectDisplay(new SharedOchiai(), new SharedOneColumnFile(fileNameRoot+"shared.ochiai")));
80 }else if (globaldata->Estimators[i] == "sharedanderberg") {
81 cDisplays.push_back(new CollectDisplay(new SharedAnderberg(), new SharedOneColumnFile(fileNameRoot+"shared.anderberg")));
82 }else if (globaldata->Estimators[i] == "sharedkulczynski") {
83 cDisplays.push_back(new CollectDisplay(new SharedKulczynski(), new SharedOneColumnFile(fileNameRoot+"shared.kulczynski")));
84 }else if (globaldata->Estimators[i] == "sharedkulczynskicody") {
85 cDisplays.push_back(new CollectDisplay(new SharedKulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"shared.kulczynskicody")));
86 }else if (globaldata->Estimators[i] == "sharedlennon") {
87 cDisplays.push_back(new CollectDisplay(new SharedLennon(), new SharedOneColumnFile(fileNameRoot+"shared.lennon")));
88 }else if (globaldata->Estimators[i] == "sharedmorisitahorn") {
89 cDisplays.push_back(new CollectDisplay(new SharedMorHorn(), new SharedOneColumnFile(fileNameRoot+"shared.morisitahorn")));
90 }else if (globaldata->Estimators[i] == "sharedbraycurtis") {
91 cDisplays.push_back(new CollectDisplay(new SharedBrayCurtis(), new SharedOneColumnFile(fileNameRoot+"shared.braycurtis")));
96 //reset calc for next command
97 globaldata->setCalc("");
100 catch(exception& e) {
101 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
105 cout << "An unknown error has occurred in the CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
111 //**********************************************************************************************************************
113 CollectSharedCommand::~CollectSharedCommand(){
120 //**********************************************************************************************************************
122 int CollectSharedCommand::execute(){
126 //if the users entered no valid calculators don't execute command
127 if (cDisplays.size() == 0) { return 0; }
129 if (format == "sharedfile") {
130 read = new ReadPhilFile(globaldata->inputFileName);
131 read->read(&*globaldata);
133 input = globaldata->ginput;
134 order = input->getSharedOrderVector();
136 //you are using a list and a groupfile
137 read = new ReadPhilFile(globaldata->inputFileName);
138 read->read(&*globaldata);
140 input = globaldata->ginput;
141 SharedList = globaldata->gSharedList;
142 order = SharedList->getSharedOrderVector();
144 set<string> orderList;
149 while(order != NULL){
150 orderList.insert(order->getLabel());
151 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
152 //create collectors curve
153 cCurve = new Collect(order, cDisplays);
154 convert(globaldata->getFreq(), freq);
155 cCurve->getSharedCurve(freq);
159 cout << order->getLabel() << '\t' << count << endl;
162 //get next line to process
163 if (format == "sharedfile") {
164 order = input->getSharedOrderVector();
166 //you are using a list and a groupfile
167 SharedList = input->getSharedListVector(); //get new list vector to process
168 if (SharedList != NULL) {
169 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
177 set<string>::iterator i;
178 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
179 if(orderList.count(*i) == 0)
180 cout << "'" << *i << "'" << " is not a valid label.\n";
181 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
183 //reset groups parameter
184 globaldata->Groups.clear(); globaldata->setGroups("");
188 catch(exception& e) {
189 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
193 cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
199 //**********************************************************************************************************************
200 void CollectSharedCommand::setGroups() {
202 //if the user has not entered specific groups to analyze then do them all
203 if (globaldata->Groups.size() != 0) {
204 if (globaldata->Groups[0] != "all") {
205 //check that groups are valid
206 for (int i = 0; i < globaldata->Groups.size(); i++) {
207 if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
208 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
209 // erase the invalid group from globaldata->Groups
210 globaldata->Groups.erase(globaldata->Groups.begin()+i);
214 //if the user only entered invalid groups
215 if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) {
216 cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl;
217 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
218 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
221 }else{//user has enter "all" and wants the default groups
222 globaldata->Groups.clear();
223 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
224 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
226 globaldata->setGroups("");
229 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
230 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
235 catch(exception& e) {
236 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
240 cout << "An unknown error has occurred in the CollectSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
245 /***********************************************************/