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();
44 util = new SharedUtil();
47 for (i=0; i<globaldata->Estimators.size(); i++) {
48 if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) {
49 if (globaldata->Estimators[i] == "sharedchao") {
50 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
51 }else if (globaldata->Estimators[i] == "sharedsobs") {
52 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
53 }else if (globaldata->Estimators[i] == "sharedace") {
54 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
55 }else if (globaldata->Estimators[i] == "jabund") {
56 cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund")));
57 }else if (globaldata->Estimators[i] == "sorensonabund") {
58 cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund")));
59 }else if (globaldata->Estimators[i] == "jclass") {
60 cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass")));
61 }else if (globaldata->Estimators[i] == "sorclass") {
62 cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass")));
63 }else if (globaldata->Estimators[i] == "jest") {
64 cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest")));
65 }else if (globaldata->Estimators[i] == "sorest") {
66 cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest")));
67 }else if (globaldata->Estimators[i] == "thetayc") {
68 cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc")));
69 }else if (globaldata->Estimators[i] == "thetan") {
70 cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan")));
71 }else if (globaldata->Estimators[i] == "kstest") {
72 cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest")));
73 }else if (globaldata->Estimators[i] == "bdiversity") {
74 cDisplays.push_back(new CollectDisplay(new BDiversity(), new SharedOneColumnFile(fileNameRoot+"bdiversity")));
75 }else if (globaldata->Estimators[i] == "sharednseqs") {
76 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
77 }else if (globaldata->Estimators[i] == "ochiai") {
78 cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai")));
79 }else if (globaldata->Estimators[i] == "anderberg") {
80 cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg")));
81 }else if (globaldata->Estimators[i] == "skulczynski") {
82 cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski")));
83 }else if (globaldata->Estimators[i] == "kulczynskicody") {
84 cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody")));
85 }else if (globaldata->Estimators[i] == "lennon") {
86 cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon")));
87 }else if (globaldata->Estimators[i] == "morisitahorn") {
88 cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn")));
89 }else if (globaldata->Estimators[i] == "braycurtis") {
90 cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis")));
95 //reset calc for next command
96 globaldata->setCalc("");
100 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
104 cout << "An unknown error has occurred in the CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
110 //**********************************************************************************************************************
112 CollectSharedCommand::~CollectSharedCommand(){
120 //**********************************************************************************************************************
122 int CollectSharedCommand::execute(){
126 //if the users entered no valid calculators don't execute command
127 if (cDisplays.size() == 0) { return 0; }
129 if (format == "sharedfile") {
130 read = new ReadOTUFile(globaldata->inputFileName);
131 read->read(&*globaldata);
133 input = globaldata->ginput;
134 order = input->getSharedOrderVector();
136 //you are using a list and a groupfile
137 read = new ReadOTUFile(globaldata->inputFileName);
138 read->read(&*globaldata);
140 input = globaldata->ginput;
141 SharedList = globaldata->gSharedList;
142 order = SharedList->getSharedOrderVector();
144 set<string> orderList;
147 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
148 util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
150 while(order != NULL){
151 orderList.insert(order->getLabel());
152 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
153 //create collectors curve
154 cCurve = new Collect(order, cDisplays);
155 convert(globaldata->getFreq(), freq);
156 cCurve->getSharedCurve(freq);
160 cout << order->getLabel() << '\t' << count << endl;
163 //get next line to process
164 if (format == "sharedfile") {
165 order = input->getSharedOrderVector();
167 //you are using a list and a groupfile
168 SharedList = input->getSharedListVector(); //get new list vector to process
169 if (SharedList != NULL) {
170 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
178 set<string>::iterator i;
179 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
180 if(orderList.count(*i) == 0)
181 cout << "'" << *i << "'" << " is not a valid label.\n";
182 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
184 //reset groups parameter
185 globaldata->Groups.clear(); globaldata->setGroups("");
189 catch(exception& e) {
190 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
194 cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
199 /***********************************************************/