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 #include "sharedkstest.h"
23 #include "sharedbdiversity.h"
24 #include "sharednseqs.h"
25 #include "sharedochiai.h"
26 #include "sharedanderbergs.h"
27 #include "sharedkulczynski.h"
28 #include "sharedkulczynskicody.h"
29 #include "sharedlennon.h"
30 #include "sharedmorisitahorn.h"
31 #include "sharedbraycurtis.h"
35 //**********************************************************************************************************************
37 CollectSharedCommand::CollectSharedCommand(){
39 globaldata = GlobalData::getInstance();
41 fileNameRoot = getRootName(globaldata->inputFileName);
42 format = globaldata->getFormat();
43 validCalculator = new ValidCalculators();
46 for (i=0; i<globaldata->Estimators.size(); i++) {
47 if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) {
48 if (globaldata->Estimators[i] == "sharedchao") {
49 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
50 }else if (globaldata->Estimators[i] == "sharedsobs") {
51 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
52 }else if (globaldata->Estimators[i] == "sharedace") {
53 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
54 }else if (globaldata->Estimators[i] == "sharedjabund") {
55 cDisplays.push_back(new CollectDisplay(new SharedJAbund(), new SharedOneColumnFile(fileNameRoot+"shared.jabund")));
56 }else if (globaldata->Estimators[i] == "sharedsorensonabund") {
57 cDisplays.push_back(new CollectDisplay(new SharedSorAbund(), new SharedOneColumnFile(fileNameRoot+"shared.sorabund")));
58 }else if (globaldata->Estimators[i] == "sharedjclass") {
59 cDisplays.push_back(new CollectDisplay(new SharedJclass(), new SharedOneColumnFile(fileNameRoot+"shared.jclass")));
60 }else if (globaldata->Estimators[i] == "sharedsorclass") {
61 cDisplays.push_back(new CollectDisplay(new SharedSorClass(), new SharedOneColumnFile(fileNameRoot+"shared.sorclass")));
62 }else if (globaldata->Estimators[i] == "sharedjest") {
63 cDisplays.push_back(new CollectDisplay(new SharedJest(), new SharedOneColumnFile(fileNameRoot+"shared.jest")));
64 }else if (globaldata->Estimators[i] == "sharedsorest") {
65 cDisplays.push_back(new CollectDisplay(new SharedSorEst(), new SharedOneColumnFile(fileNameRoot+"shared.sorest")));
66 }else if (globaldata->Estimators[i] == "sharedthetayc") {
67 cDisplays.push_back(new CollectDisplay(new SharedThetaYC(), new SharedOneColumnFile(fileNameRoot+"shared.thetayc")));
68 }else if (globaldata->Estimators[i] == "sharedthetan") {
69 cDisplays.push_back(new CollectDisplay(new SharedThetaN(), new SharedOneColumnFile(fileNameRoot+"shared.thetan")));
70 }else if (globaldata->Estimators[i] == "sharedkstest") {
71 cDisplays.push_back(new CollectDisplay(new SharedKSTest(), new SharedOneColumnFile(fileNameRoot+"shared.kstest")));
72 }else if (globaldata->Estimators[i] == "sharedbdiversity") {
73 cDisplays.push_back(new CollectDisplay(new SharedBDiversity(), new SharedOneColumnFile(fileNameRoot+"shared.bdiversity")));
74 }else if (globaldata->Estimators[i] == "sharednseqs") {
75 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
76 }else if (globaldata->Estimators[i] == "sharedochiai") {
77 cDisplays.push_back(new CollectDisplay(new SharedOchiai(), new SharedOneColumnFile(fileNameRoot+"shared.ochiai")));
78 }else if (globaldata->Estimators[i] == "sharedanderberg") {
79 cDisplays.push_back(new CollectDisplay(new SharedAnderberg(), new SharedOneColumnFile(fileNameRoot+"shared.anderberg")));
80 }else if (globaldata->Estimators[i] == "sharedkulczynski") {
81 cDisplays.push_back(new CollectDisplay(new SharedKulczynski(), new SharedOneColumnFile(fileNameRoot+"shared.kulczynski")));
82 }else if (globaldata->Estimators[i] == "sharedkulczynskicody") {
83 cDisplays.push_back(new CollectDisplay(new SharedKulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"shared.kulczynskicody")));
84 }else if (globaldata->Estimators[i] == "sharedlennon") {
85 cDisplays.push_back(new CollectDisplay(new SharedLennon(), new SharedOneColumnFile(fileNameRoot+"shared.lennon")));
86 }else if (globaldata->Estimators[i] == "sharedmorisitahorn") {
87 cDisplays.push_back(new CollectDisplay(new SharedMorHorn(), new SharedOneColumnFile(fileNameRoot+"shared.morisitahorn")));
88 }else if (globaldata->Estimators[i] == "sharedbraycurtis") {
89 cDisplays.push_back(new CollectDisplay(new SharedBrayCurtis(), new SharedOneColumnFile(fileNameRoot+"shared.braycurtis")));
94 //reset calc for next command
95 globaldata->setCalc("");
99 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
103 cout << "An unknown error has occurred in the CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
109 //**********************************************************************************************************************
111 CollectSharedCommand::~CollectSharedCommand(){
118 //**********************************************************************************************************************
120 int CollectSharedCommand::execute(){
124 //if the users entered no valid calculators don't execute command
125 if (cDisplays.size() == 0) { return 0; }
127 if (format == "sharedfile") {
128 read = new ReadPhilFile(globaldata->inputFileName);
129 read->read(&*globaldata);
131 input = globaldata->ginput;
132 order = input->getSharedOrderVector();
134 //you are using a list and a groupfile
135 read = new ReadPhilFile(globaldata->inputFileName);
136 read->read(&*globaldata);
138 input = globaldata->ginput;
139 SharedList = globaldata->gSharedList;
140 order = SharedList->getSharedOrderVector();
142 set<string> orderList;
147 while(order != NULL){
148 orderList.insert(order->getLabel());
149 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
150 //create collectors curve
151 cCurve = new Collect(order, cDisplays);
152 convert(globaldata->getFreq(), freq);
153 cCurve->getSharedCurve(freq);
157 cout << order->getLabel() << '\t' << count << endl;
160 //get next line to process
161 if (format == "sharedfile") {
162 order = input->getSharedOrderVector();
164 //you are using a list and a groupfile
165 SharedList = input->getSharedListVector(); //get new list vector to process
166 if (SharedList != NULL) {
167 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
175 set<string>::iterator i;
176 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
177 if(orderList.count(*i) == 0)
178 cout << "'" << *i << "'" << " is not a valid label.\n";
179 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
181 //reset groups parameter
182 globaldata->Groups.clear(); globaldata->setGroups("");
186 catch(exception& e) {
187 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
191 cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
197 //**********************************************************************************************************************
198 void CollectSharedCommand::setGroups() {
200 //if the user has not entered specific groups to analyze then do them all
201 if (globaldata->Groups.size() != 0) {
202 if (globaldata->Groups[0] != "all") {
203 //check that groups are valid
204 for (int i = 0; i < globaldata->Groups.size(); i++) {
205 if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
206 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
207 // erase the invalid group from globaldata->Groups
208 globaldata->Groups.erase(globaldata->Groups.begin()+i);
212 //if the user only entered invalid groups
213 if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) {
214 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;
215 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
216 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
219 }else{//user has enter "all" and wants the default groups
220 globaldata->Groups.clear();
221 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
222 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
224 globaldata->setGroups("");
227 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
228 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
233 catch(exception& e) {
234 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
238 cout << "An unknown error has occurred in the CollectSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
243 /***********************************************************/