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"
25 //**********************************************************************************************************************
27 CollectSharedCommand::CollectSharedCommand(){
29 globaldata = GlobalData::getInstance();
31 fileNameRoot = getRootName(globaldata->inputFileName);
32 format = globaldata->getFormat();
33 validCalculator = new ValidCalculators();
36 for (i=0; i<globaldata->Estimators.size(); i++) {
37 if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) {
38 if (globaldata->Estimators[i] == "sharedchao") {
39 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
40 }else if (globaldata->Estimators[i] == "sharedsobs") {
41 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
42 }else if (globaldata->Estimators[i] == "sharedace") {
43 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
44 }else if (globaldata->Estimators[i] == "sharedjabund") {
45 cDisplays.push_back(new CollectDisplay(new SharedJAbund(), new SharedOneColumnFile(fileNameRoot+"shared.jabund")));
46 }else if (globaldata->Estimators[i] == "sharedsorensonabund") {
47 cDisplays.push_back(new CollectDisplay(new SharedSorAbund(), new SharedOneColumnFile(fileNameRoot+"shared.sorabund")));
48 }else if (globaldata->Estimators[i] == "sharedjclass") {
49 cDisplays.push_back(new CollectDisplay(new SharedJclass(), new SharedOneColumnFile(fileNameRoot+"shared.jclass")));
50 }else if (globaldata->Estimators[i] == "sharedsorclass") {
51 cDisplays.push_back(new CollectDisplay(new SharedSorClass(), new SharedOneColumnFile(fileNameRoot+"shared.sorclass")));
52 }else if (globaldata->Estimators[i] == "sharedjest") {
53 cDisplays.push_back(new CollectDisplay(new SharedJest(), new SharedOneColumnFile(fileNameRoot+"shared.jest")));
54 }else if (globaldata->Estimators[i] == "sharedsorest") {
55 cDisplays.push_back(new CollectDisplay(new SharedSorEst(), new SharedOneColumnFile(fileNameRoot+"shared.sorest")));
56 }else if (globaldata->Estimators[i] == "sharedthetayc") {
57 cDisplays.push_back(new CollectDisplay(new SharedThetaYC(), new SharedOneColumnFile(fileNameRoot+"shared.thetayc")));
58 }else if (globaldata->Estimators[i] == "sharedthetan") {
59 cDisplays.push_back(new CollectDisplay(new SharedThetaN(), new SharedOneColumnFile(fileNameRoot+"shared.thetan")));
60 }else if (globaldata->Estimators[i] == "sharednseqs") {
61 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
67 //reset calc for next command
68 globaldata->setCalc("");
72 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
76 cout << "An unknown error has occurred in the CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82 //**********************************************************************************************************************
84 CollectSharedCommand::~CollectSharedCommand(){
91 //**********************************************************************************************************************
93 int CollectSharedCommand::execute(){
97 //if the users entered no valid calculators don't execute command
98 if (cDisplays.size() == 0) { return 0; }
100 if (format == "sharedfile") {
101 read = new ReadPhilFile(globaldata->inputFileName);
102 read->read(&*globaldata);
104 input = globaldata->ginput;
105 order = input->getSharedOrderVector();
107 //you are using a list and a groupfile
108 read = new ReadPhilFile(globaldata->inputFileName);
109 read->read(&*globaldata);
111 input = globaldata->ginput;
112 SharedList = globaldata->gSharedList;
113 order = SharedList->getSharedOrderVector();
115 set<string> orderList;
120 while(order != NULL){
121 orderList.insert(order->getLabel());
122 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
123 //create collectors curve
124 cCurve = new Collect(order, cDisplays);
125 convert(globaldata->getFreq(), freq);
126 cCurve->getSharedCurve(freq);
130 cout << order->getLabel() << '\t' << count << endl;
133 //get next line to process
134 if (format == "sharedfile") {
135 order = input->getSharedOrderVector();
137 //you are using a list and a groupfile
138 SharedList = input->getSharedListVector(); //get new list vector to process
139 if (SharedList != NULL) {
140 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
148 set<string>::iterator i;
149 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
150 if(orderList.count(*i) == 0)
151 cout << "'" << *i << "'" << " is not a valid label.\n";
152 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
154 //reset groups parameter
155 globaldata->Groups.clear(); globaldata->setGroups("");
159 catch(exception& e) {
160 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
164 cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
170 //**********************************************************************************************************************
171 void CollectSharedCommand::setGroups() {
173 //if the user has not entered specific groups to analyze then do them all
174 if (globaldata->Groups.size() != 0) {
175 if (globaldata->Groups[0] != "all") {
176 //check that groups are valid
177 for (int i = 0; i < globaldata->Groups.size(); i++) {
178 if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
179 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
180 // erase the invalid group from globaldata->Groups
181 globaldata->Groups.erase(globaldata->Groups.begin()+i);
185 //if the user only entered invalid groups
186 if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) {
187 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;
188 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
189 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
192 }else{//user has enter "all" and wants the default groups
193 globaldata->Groups.clear();
194 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
195 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
197 globaldata->setGroups("");
200 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
201 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
206 catch(exception& e) {
207 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
211 cout << "An unknown error has occurred in the CollectSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
216 /***********************************************************/