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 "sharednseqs.h"
23 #include "sharedochiai.h"
24 #include "sharedanderberg.h"
25 #include "sharedkulczynski.h"
26 #include "sharedkulczynskicody.h"
27 #include "sharedlennon.h"
28 #include "sharedmorisitahorn.h"
29 #include "sharedbraycurtis.h"
32 //**********************************************************************************************************************
34 CollectSharedCommand::CollectSharedCommand(){
36 globaldata = GlobalData::getInstance();
38 fileNameRoot = getRootName(globaldata->inputFileName);
39 format = globaldata->getFormat();
40 validCalculator = new ValidCalculators();
43 for (i=0; i<globaldata->Estimators.size(); i++) {
44 if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) {
45 if (globaldata->Estimators[i] == "sharedchao") {
46 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
47 }else if (globaldata->Estimators[i] == "sharedsobs") {
48 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
49 }else if (globaldata->Estimators[i] == "sharedace") {
50 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
51 }else if (globaldata->Estimators[i] == "sharedjabund") {
52 cDisplays.push_back(new CollectDisplay(new SharedJAbund(), new SharedOneColumnFile(fileNameRoot+"shared.jabund")));
53 }else if (globaldata->Estimators[i] == "sharedsorensonabund") {
54 cDisplays.push_back(new CollectDisplay(new SharedSorAbund(), new SharedOneColumnFile(fileNameRoot+"shared.sorabund")));
55 }else if (globaldata->Estimators[i] == "sharedjclass") {
56 cDisplays.push_back(new CollectDisplay(new SharedJclass(), new SharedOneColumnFile(fileNameRoot+"shared.jclass")));
57 }else if (globaldata->Estimators[i] == "sharedsorclass") {
58 cDisplays.push_back(new CollectDisplay(new SharedSorClass(), new SharedOneColumnFile(fileNameRoot+"shared.sorclass")));
59 }else if (globaldata->Estimators[i] == "sharedjest") {
60 cDisplays.push_back(new CollectDisplay(new SharedJest(), new SharedOneColumnFile(fileNameRoot+"shared.jest")));
61 }else if (globaldata->Estimators[i] == "sharedsorest") {
62 cDisplays.push_back(new CollectDisplay(new SharedSorEst(), new SharedOneColumnFile(fileNameRoot+"shared.sorest")));
63 }else if (globaldata->Estimators[i] == "sharedthetayc") {
64 cDisplays.push_back(new CollectDisplay(new SharedThetaYC(), new SharedOneColumnFile(fileNameRoot+"shared.thetayc")));
65 }else if (globaldata->Estimators[i] == "sharedthetan") {
66 cDisplays.push_back(new CollectDisplay(new SharedThetaN(), new SharedOneColumnFile(fileNameRoot+"shared.thetan")));
67 }else if (globaldata->Estimators[i] == "sharednseqs") {
68 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
69 }else if (globaldata->Estimators[i] == "sharedochiai") {
70 cDisplays.push_back(new CollectDisplay(new SharedOchiai(), new SharedOneColumnFile(fileNameRoot+"shared.ochiai")));
71 }else if (globaldata->Estimators[i] == "sharedanderberg") {
72 cDisplays.push_back(new CollectDisplay(new SharedAnderberg(), new SharedOneColumnFile(fileNameRoot+"shared.anderberg")));
73 }else if (globaldata->Estimators[i] == "sharedkulczynski") {
74 cDisplays.push_back(new CollectDisplay(new SharedKulczynski(), new SharedOneColumnFile(fileNameRoot+"shared.kulczynski")));
75 }else if (globaldata->Estimators[i] == "sharedkulczynskicody") {
76 cDisplays.push_back(new CollectDisplay(new SharedKulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"shared.kulczynskicody")));
77 }else if (globaldata->Estimators[i] == "sharedlennon") {
78 cDisplays.push_back(new CollectDisplay(new SharedLennon(), new SharedOneColumnFile(fileNameRoot+"shared.lennon")));
79 }else if (globaldata->Estimators[i] == "sharedmorisitahorn") {
80 cDisplays.push_back(new CollectDisplay(new SharedMorHorn(), new SharedOneColumnFile(fileNameRoot+"shared.morisitahorn")));
81 }else if (globaldata->Estimators[i] == "sharedbraycurtis") {
82 cDisplays.push_back(new CollectDisplay(new SharedBrayCurtis(), new SharedOneColumnFile(fileNameRoot+"shared.braycurtis")));
87 //reset calc for next command
88 globaldata->setCalc("");
92 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
96 cout << "An unknown error has occurred in the CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
102 //**********************************************************************************************************************
104 CollectSharedCommand::~CollectSharedCommand(){
111 //**********************************************************************************************************************
113 int CollectSharedCommand::execute(){
117 //if the users entered no valid calculators don't execute command
118 if (cDisplays.size() == 0) { return 0; }
120 if (format == "sharedfile") {
121 read = new ReadPhilFile(globaldata->inputFileName);
122 read->read(&*globaldata);
124 input = globaldata->ginput;
125 order = input->getSharedOrderVector();
127 //you are using a list and a groupfile
128 read = new ReadPhilFile(globaldata->inputFileName);
129 read->read(&*globaldata);
131 input = globaldata->ginput;
132 SharedList = globaldata->gSharedList;
133 order = SharedList->getSharedOrderVector();
135 set<string> orderList;
140 while(order != NULL){
141 orderList.insert(order->getLabel());
142 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
143 //create collectors curve
144 cCurve = new Collect(order, cDisplays);
145 convert(globaldata->getFreq(), freq);
146 cCurve->getSharedCurve(freq);
150 cout << order->getLabel() << '\t' << count << endl;
153 //get next line to process
154 if (format == "sharedfile") {
155 order = input->getSharedOrderVector();
157 //you are using a list and a groupfile
158 SharedList = input->getSharedListVector(); //get new list vector to process
159 if (SharedList != NULL) {
160 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
168 set<string>::iterator i;
169 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
170 if(orderList.count(*i) == 0)
171 cout << "'" << *i << "'" << " is not a valid label.\n";
172 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
174 //reset groups parameter
175 globaldata->Groups.clear(); globaldata->setGroups("");
179 catch(exception& e) {
180 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
184 cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
190 //**********************************************************************************************************************
191 void CollectSharedCommand::setGroups() {
193 //if the user has not entered specific groups to analyze then do them all
194 if (globaldata->Groups.size() != 0) {
195 if (globaldata->Groups[0] != "all") {
196 //check that groups are valid
197 for (int i = 0; i < globaldata->Groups.size(); i++) {
198 if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
199 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
200 // erase the invalid group from globaldata->Groups
201 globaldata->Groups.erase(globaldata->Groups.begin()+i);
205 //if the user only entered invalid groups
206 if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) {
207 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;
208 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
209 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
212 }else{//user has enter "all" and wants the default groups
213 globaldata->Groups.clear();
214 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
215 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
217 globaldata->setGroups("");
220 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
221 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
226 catch(exception& e) {
227 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
231 cout << "An unknown error has occurred in the CollectSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
236 /***********************************************************/