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"
27 //**********************************************************************************************************************
29 CollectSharedCommand::CollectSharedCommand(){
31 globaldata = GlobalData::getInstance();
33 fileNameRoot = getRootName(globaldata->inputFileName);
34 format = globaldata->getFormat();
35 validCalculator = new ValidCalculators();
38 for (i=0; i<globaldata->Estimators.size(); i++) {
39 if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) {
40 if (globaldata->Estimators[i] == "sharedchao") {
41 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
42 }else if (globaldata->Estimators[i] == "sharedsobs") {
43 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
44 }else if (globaldata->Estimators[i] == "sharedace") {
45 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
46 }else if (globaldata->Estimators[i] == "sharedjabund") {
47 cDisplays.push_back(new CollectDisplay(new SharedJAbund(), new SharedOneColumnFile(fileNameRoot+"shared.jabund")));
48 }else if (globaldata->Estimators[i] == "sharedsorensonabund") {
49 cDisplays.push_back(new CollectDisplay(new SharedSorAbund(), new SharedOneColumnFile(fileNameRoot+"shared.sorabund")));
50 }else if (globaldata->Estimators[i] == "sharedjclass") {
51 cDisplays.push_back(new CollectDisplay(new SharedJclass(), new SharedOneColumnFile(fileNameRoot+"shared.jclass")));
52 }else if (globaldata->Estimators[i] == "sharedsorclass") {
53 cDisplays.push_back(new CollectDisplay(new SharedSorClass(), new SharedOneColumnFile(fileNameRoot+"shared.sorclass")));
54 }else if (globaldata->Estimators[i] == "sharedjest") {
55 cDisplays.push_back(new CollectDisplay(new SharedJest(), new SharedOneColumnFile(fileNameRoot+"shared.jest")));
56 }else if (globaldata->Estimators[i] == "sharedsorest") {
57 cDisplays.push_back(new CollectDisplay(new SharedSorEst(), new SharedOneColumnFile(fileNameRoot+"shared.sorest")));
58 }else if (globaldata->Estimators[i] == "sharedthetayc") {
59 cDisplays.push_back(new CollectDisplay(new SharedThetaYC(), new SharedOneColumnFile(fileNameRoot+"shared.thetayc")));
60 }else if (globaldata->Estimators[i] == "sharedthetan") {
61 cDisplays.push_back(new CollectDisplay(new SharedThetaN(), new SharedOneColumnFile(fileNameRoot+"shared.thetan")));
62 }else if (globaldata->Estimators[i] == "sharednseqs") {
63 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
64 }else if (globaldata->Estimators[i] == "sharedochiai") {
65 cDisplays.push_back(new CollectDisplay(new SharedOchiai(), new SharedOneColumnFile(fileNameRoot+"shared.ochiai")));
66 }else if (globaldata->Estimators[i] == "sharedanderberg") {
67 cDisplays.push_back(new CollectDisplay(new SharedAnderberg(), new SharedOneColumnFile(fileNameRoot+"shared.anderberg")));
73 //reset calc for next command
74 globaldata->setCalc("");
78 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82 cout << "An unknown error has occurred in the CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
88 //**********************************************************************************************************************
90 CollectSharedCommand::~CollectSharedCommand(){
97 //**********************************************************************************************************************
99 int CollectSharedCommand::execute(){
103 //if the users entered no valid calculators don't execute command
104 if (cDisplays.size() == 0) { return 0; }
106 if (format == "sharedfile") {
107 read = new ReadPhilFile(globaldata->inputFileName);
108 read->read(&*globaldata);
110 input = globaldata->ginput;
111 order = input->getSharedOrderVector();
113 //you are using a list and a groupfile
114 read = new ReadPhilFile(globaldata->inputFileName);
115 read->read(&*globaldata);
117 input = globaldata->ginput;
118 SharedList = globaldata->gSharedList;
119 order = SharedList->getSharedOrderVector();
121 set<string> orderList;
126 while(order != NULL){
127 orderList.insert(order->getLabel());
128 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
129 //create collectors curve
130 cCurve = new Collect(order, cDisplays);
131 convert(globaldata->getFreq(), freq);
132 cCurve->getSharedCurve(freq);
136 cout << order->getLabel() << '\t' << count << endl;
139 //get next line to process
140 if (format == "sharedfile") {
141 order = input->getSharedOrderVector();
143 //you are using a list and a groupfile
144 SharedList = input->getSharedListVector(); //get new list vector to process
145 if (SharedList != NULL) {
146 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
154 set<string>::iterator i;
155 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
156 if(orderList.count(*i) == 0)
157 cout << "'" << *i << "'" << " is not a valid label.\n";
158 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
160 //reset groups parameter
161 globaldata->Groups.clear(); globaldata->setGroups("");
165 catch(exception& e) {
166 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
170 cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
176 //**********************************************************************************************************************
177 void CollectSharedCommand::setGroups() {
179 //if the user has not entered specific groups to analyze then do them all
180 if (globaldata->Groups.size() != 0) {
181 if (globaldata->Groups[0] != "all") {
182 //check that groups are valid
183 for (int i = 0; i < globaldata->Groups.size(); i++) {
184 if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
185 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
186 // erase the invalid group from globaldata->Groups
187 globaldata->Groups.erase(globaldata->Groups.begin()+i);
191 //if the user only entered invalid groups
192 if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) {
193 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;
194 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
195 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
198 }else{//user has enter "all" and wants the default groups
199 globaldata->Groups.clear();
200 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
201 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
203 globaldata->setGroups("");
206 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
207 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
212 catch(exception& e) {
213 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
217 cout << "An unknown error has occurred in the CollectSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
222 /***********************************************************/