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 "whittaker.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"
32 #include "sharedjackknife.h"
33 #include "sharedwhittaker.h"
37 //**********************************************************************************************************************
39 CollectSharedCommand::CollectSharedCommand(){
41 globaldata = GlobalData::getInstance();
43 fileNameRoot = getRootName(globaldata->inputFileName);
44 format = globaldata->getFormat();
45 validCalculator = new ValidCalculators();
46 util = new SharedUtil();
49 for (i=0; i<globaldata->Estimators.size(); i++) {
50 if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) {
51 if (globaldata->Estimators[i] == "sharedchao") {
52 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
53 }else if (globaldata->Estimators[i] == "sharedsobs") {
54 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
55 }else if (globaldata->Estimators[i] == "sharedace") {
56 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
57 }else if (globaldata->Estimators[i] == "jabund") {
58 cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund")));
59 }else if (globaldata->Estimators[i] == "sorabund") {
60 cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund")));
61 }else if (globaldata->Estimators[i] == "jclass") {
62 cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass")));
63 }else if (globaldata->Estimators[i] == "sorclass") {
64 cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass")));
65 }else if (globaldata->Estimators[i] == "jest") {
66 cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest")));
67 }else if (globaldata->Estimators[i] == "sorest") {
68 cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest")));
69 }else if (globaldata->Estimators[i] == "thetayc") {
70 cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc")));
71 }else if (globaldata->Estimators[i] == "thetan") {
72 cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan")));
73 }else if (globaldata->Estimators[i] == "kstest") {
74 cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest")));
75 }else if (globaldata->Estimators[i] == "whittaker") {
76 cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+"whittaker")));
77 }else if (globaldata->Estimators[i] == "sharednseqs") {
78 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
80 }else if (globaldata->Estimators[i] == "ochiai") {
81 cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai")));
82 }else if (globaldata->Estimators[i] == "anderberg") {
83 cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg")));
84 }else if (globaldata->Estimators[i] == "skulczynski") {
85 cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski")));
86 }else if (globaldata->Estimators[i] == "kulczynskicody") {
87 cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody")));
88 }else if (globaldata->Estimators[i] == "lennon") {
89 cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon")));
90 }else if (globaldata->Estimators[i] == "morisitahorn") {
91 cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn")));
92 }else if (globaldata->Estimators[i] == "braycurtis") {
93 cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis")));
98 //reset calc for next command
99 globaldata->setCalc("");
102 catch(exception& e) {
103 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
107 cout << "An unknown error has occurred in the CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
113 //**********************************************************************************************************************
115 CollectSharedCommand::~CollectSharedCommand(){
123 //**********************************************************************************************************************
125 int CollectSharedCommand::execute(){
129 //if the users entered no valid calculators don't execute command
130 if (cDisplays.size() == 0) { return 0; }
132 if (format == "sharedfile") {
133 read = new ReadOTUFile(globaldata->inputFileName);
134 read->read(&*globaldata);
136 input = globaldata->ginput;
137 order = input->getSharedOrderVector();
139 //you are using a list and a groupfile
140 read = new ReadOTUFile(globaldata->inputFileName);
141 read->read(&*globaldata);
143 input = globaldata->ginput;
144 SharedList = globaldata->gSharedList;
145 order = SharedList->getSharedOrderVector();
147 set<string> orderList;
150 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
151 util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
153 while(order != NULL){
154 orderList.insert(order->getLabel());
155 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
156 //create collectors curve
157 cCurve = new Collect(order, cDisplays);
158 convert(globaldata->getFreq(), freq);
159 cCurve->getSharedCurve(freq);
163 cout << order->getLabel() << '\t' << count << endl;
166 //get next line to process
167 if (format == "sharedfile") {
168 order = input->getSharedOrderVector();
170 //you are using a list and a groupfile
171 SharedList = input->getSharedListVector(); //get new list vector to process
172 if (SharedList != NULL) {
173 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
181 set<string>::iterator i;
182 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
183 if(orderList.count(*i) == 0)
184 cout << "'" << *i << "'" << " is not a valid label.\n";
185 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
187 //reset groups parameter
188 globaldata->Groups.clear(); globaldata->setGroups("");
192 catch(exception& e) {
193 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
197 cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
202 /***********************************************************/