2 * summarysharedcommand.cpp
5 * Created by Sarah Westcott on 1/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "summarysharedcommand.h"
11 #include "sharedsobscollectsummary.h"
12 #include "sharedchao1.h"
13 #include "sharedace.h"
14 #include "sharednseqs.h"
15 #include "sharedjabund.h"
16 #include "sharedsorabund.h"
17 #include "sharedjclass.h"
18 #include "sharedsorclass.h"
19 #include "sharedjest.h"
20 #include "sharedsorest.h"
21 #include "sharedthetayc.h"
22 #include "sharedthetan.h"
23 #include "sharedkstest.h"
24 #include "whittaker.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"
34 //**********************************************************************************************************************
36 SummarySharedCommand::SummarySharedCommand(){
38 globaldata = GlobalData::getInstance();
39 outputFileName = ((getRootName(globaldata->inputFileName)) + "shared.summary");
40 openOutputFile(outputFileName, outputFileHandle);
41 format = globaldata->getFormat();
42 validCalculator = new ValidCalculators();
43 util = new SharedUtil();
47 for (i=0; i<globaldata->Estimators.size(); i++) {
48 if (validCalculator->isValidCalculator("sharedsummary", globaldata->Estimators[i]) == true) {
49 if (globaldata->Estimators[i] == "sharedsobs") {
50 sumCalculators.push_back(new SharedSobsCS());
51 }else if (globaldata->Estimators[i] == "sharedchao") {
52 sumCalculators.push_back(new SharedChao1());
53 }else if (globaldata->Estimators[i] == "sharedace") {
54 sumCalculators.push_back(new SharedAce());
55 }else if (globaldata->Estimators[i] == "jabund") {
56 sumCalculators.push_back(new JAbund());
57 }else if (globaldata->Estimators[i] == "sorabund") {
58 sumCalculators.push_back(new SorAbund());
59 }else if (globaldata->Estimators[i] == "jclass") {
60 sumCalculators.push_back(new Jclass());
61 }else if (globaldata->Estimators[i] == "sorclass") {
62 sumCalculators.push_back(new SorClass());
63 }else if (globaldata->Estimators[i] == "jest") {
64 sumCalculators.push_back(new Jest());
65 }else if (globaldata->Estimators[i] == "sorest") {
66 sumCalculators.push_back(new SorEst());
67 }else if (globaldata->Estimators[i] == "thetayc") {
68 sumCalculators.push_back(new ThetaYC());
69 }else if (globaldata->Estimators[i] == "thetan") {
70 sumCalculators.push_back(new ThetaN());
71 }else if (globaldata->Estimators[i] == "kstest") {
72 sumCalculators.push_back(new KSTest());
73 }else if (globaldata->Estimators[i] == "sharednseqs") {
74 sumCalculators.push_back(new SharedNSeqs());
75 }else if (globaldata->Estimators[i] == "ochiai") {
76 sumCalculators.push_back(new Ochiai());
77 }else if (globaldata->Estimators[i] == "anderberg") {
78 sumCalculators.push_back(new Anderberg());
79 }else if (globaldata->Estimators[i] == "kulczynski") {
80 sumCalculators.push_back(new Kulczynski());
81 }else if (globaldata->Estimators[i] == "kulczynskicody") {
82 sumCalculators.push_back(new KulczynskiCody());
83 }else if (globaldata->Estimators[i] == "lennon") {
84 sumCalculators.push_back(new Lennon());
85 }else if (globaldata->Estimators[i] == "morisitahorn") {
86 sumCalculators.push_back(new MorHorn());
87 }else if (globaldata->Estimators[i] == "braycurtis") {
88 sumCalculators.push_back(new BrayCurtis());
89 }else if (globaldata->Estimators[i] == "whittaker") {
90 sumCalculators.push_back(new Whittaker());
94 //reset calc for next command
95 globaldata->setCalc("");
99 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
103 cout << "An unknown error has occurred in the SummarySharedCommand class function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
107 //**********************************************************************************************************************
109 SummarySharedCommand::~SummarySharedCommand(){
115 //**********************************************************************************************************************
117 int SummarySharedCommand::execute(){
121 //if the users entered no valid calculators don't execute command
122 if (sumCalculators.size() == 0) { return 0; }
123 //check if any calcs can do multiples
125 for (int i = 0; i < sumCalculators.size(); i++) {
126 if (sumCalculators[i]->getMultiple() == true) { mult = true; }
130 if (format == "sharedfile") {
131 read = new ReadOTUFile(globaldata->inputFileName);
132 read->read(&*globaldata);
134 input = globaldata->ginput;
135 order = input->getSharedOrderVector();
137 //you are using a list and a groupfile
138 read = new ReadOTUFile(globaldata->inputFileName);
139 read->read(&*globaldata);
141 input = globaldata->ginput;
142 SharedList = globaldata->gSharedList;
143 order = SharedList->getSharedOrderVector();
147 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "summary");
149 //output estimator names as column headers
150 outputFileHandle << "label" <<'\t' << "comparison" << '\t';
151 for(int i=0;i<sumCalculators.size();i++){
152 outputFileHandle << '\t' << sumCalculators[i]->getName();
154 outputFileHandle << endl;
156 //create file and put column headers for multiple groups file
158 outAllFileName = ((getRootName(globaldata->inputFileName)) + "sharedmultiple.summary");
159 openOutputFile(outAllFileName, outAll);
161 outAll << "label" <<'\t' << "comparison" << '\t';
162 for(int i=0;i<sumCalculators.size();i++){
163 if (sumCalculators[i]->getMultiple() == true) {
164 outAll << '\t' << sumCalculators[i]->getName();
170 while(order != NULL){
172 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
174 cout << order->getLabel() << '\t' << count << endl;
175 util->getSharedVectors(globaldata->Groups, lookup, order); //fills group vectors from order vector. //fills group vectors from order vector.
177 //loop through calculators and add to file all for all calcs that can do mutiple groups
180 outAll << order->getLabel() << '\t';
182 //output groups names
183 string outNames = "";
184 for (int j = 0; j < lookup.size(); j++) {
185 outNames += lookup[j]->getGroup() + "-";
187 outNames = outNames.substr(0, outNames.length()-1); //rip off extra '-';
188 outAll << outNames << '\t';
190 for(int i=0;i<sumCalculators.size();i++){
191 if (sumCalculators[i]->getMultiple() == true) {
192 sumCalculators[i]->getValues(lookup);
194 sumCalculators[i]->print(outAll);
201 vector<SharedRAbundVector*> subset;
202 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
203 for (int l = n; l < lookup.size(); l++) {
205 outputFileHandle << order->getLabel() << '\t';
207 subset.clear(); //clear out old pair of sharedrabunds
208 //add new pair of sharedrabunds
209 subset.push_back(lookup[k]); subset.push_back(lookup[l]);
211 //sort groups to be alphanumeric
212 if (lookup[k]->getGroup() > lookup[l]->getGroup()) {
213 outputFileHandle << (lookup[l]->getGroup() +'\t' + lookup[k]->getGroup()) << '\t'; //print out groups
215 outputFileHandle << (lookup[k]->getGroup() +'\t' + lookup[l]->getGroup()) << '\t'; //print out groups
218 for(int i=0;i<sumCalculators.size();i++) {
219 sumCalculators[i]->getValues(subset); //saves the calculator outputs
220 outputFileHandle << '\t';
221 sumCalculators[i]->print(outputFileHandle);
223 outputFileHandle << endl;
229 //get next line to process
230 if (format == "sharedfile") {
231 order = input->getSharedOrderVector();
233 //you are using a list and a groupfile
234 SharedList = input->getSharedListVector(); //get new list vector to process
235 if (SharedList != NULL) {
236 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
244 //reset groups parameter
245 globaldata->Groups.clear(); globaldata->setGroups("");
249 catch(exception& e) {
250 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
254 cout << "An unknown error has occurred in the SummarySharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
259 /***********************************************************/