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 "sharedbdiversity.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();
46 for (i=0; i<globaldata->Estimators.size(); i++) {
47 if (validCalculator->isValidCalculator("sharedsummary", globaldata->Estimators[i]) == true) {
48 if (globaldata->Estimators[i] == "sharedsobs") {
49 sumCalculators.push_back(new SharedSobsCS());
50 }else if (globaldata->Estimators[i] == "sharedchao") {
51 sumCalculators.push_back(new SharedChao1());
52 }else if (globaldata->Estimators[i] == "sharedace") {
53 sumCalculators.push_back(new SharedAce());
54 }else if (globaldata->Estimators[i] == "jabund") {
55 sumCalculators.push_back(new JAbund());
56 }else if (globaldata->Estimators[i] == "sorensonabund") {
57 sumCalculators.push_back(new SorAbund());
58 }else if (globaldata->Estimators[i] == "jclass") {
59 sumCalculators.push_back(new Jclass());
60 }else if (globaldata->Estimators[i] == "sorclass") {
61 sumCalculators.push_back(new SorClass());
62 }else if (globaldata->Estimators[i] == "jest") {
63 sumCalculators.push_back(new Jest());
64 }else if (globaldata->Estimators[i] == "sorest") {
65 sumCalculators.push_back(new SorEst());
66 }else if (globaldata->Estimators[i] == "thetayc") {
67 sumCalculators.push_back(new ThetaYC());
68 }else if (globaldata->Estimators[i] == "thetan") {
69 sumCalculators.push_back(new ThetaN());
70 }else if (globaldata->Estimators[i] == "kstest") {
71 sumCalculators.push_back(new KSTest());
72 }else if (globaldata->Estimators[i] == "sharednseqs") {
73 sumCalculators.push_back(new SharedNSeqs());
74 }else if (globaldata->Estimators[i] == "ochiai") {
75 sumCalculators.push_back(new Ochiai());
76 }else if (globaldata->Estimators[i] == "anderberg") {
77 sumCalculators.push_back(new Anderberg());
78 }else if (globaldata->Estimators[i] == "kulczynski") {
79 sumCalculators.push_back(new Kulczynski());
80 }else if (globaldata->Estimators[i] == "kulczynskicody") {
81 sumCalculators.push_back(new KulczynskiCody());
82 }else if (globaldata->Estimators[i] == "lennon") {
83 sumCalculators.push_back(new Lennon());
84 }else if (globaldata->Estimators[i] == "morisitahorn") {
85 sumCalculators.push_back(new MorHorn());
86 }else if (globaldata->Estimators[i] == "braycurtis") {
87 sumCalculators.push_back(new BrayCurtis());
89 else if (globaldata->Estimators[i] == "bdiversity") {
90 sumCalculators.push_back(new BDiversity());
95 //reset calc for next command
96 globaldata->setCalc("");
100 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
104 cout << "An unknown error has occurred in the SummarySharedCommand class function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
108 //**********************************************************************************************************************
110 SummarySharedCommand::~SummarySharedCommand(){
116 //**********************************************************************************************************************
118 int SummarySharedCommand::execute(){
122 //if the users entered no valid calculators don't execute command
123 if (sumCalculators.size() == 0) { return 0; }
125 if (format == "sharedfile") {
126 read = new ReadOTUFile(globaldata->inputFileName);
127 read->read(&*globaldata);
129 input = globaldata->ginput;
130 order = input->getSharedOrderVector();
132 //you are using a list and a groupfile
133 read = new ReadOTUFile(globaldata->inputFileName);
134 read->read(&*globaldata);
136 input = globaldata->ginput;
137 SharedList = globaldata->gSharedList;
138 order = SharedList->getSharedOrderVector();
142 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "summary");
144 //output estimator names as column headers
145 outputFileHandle << "label" <<'\t' << "comparison" << '\t';
146 for(int i=0;i<sumCalculators.size();i++){
147 outputFileHandle << '\t' << sumCalculators[i]->getName();
149 outputFileHandle << endl;
151 while(order != NULL){
153 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
155 cout << order->getLabel() << '\t' << count << endl;
156 util->getSharedVectors(globaldata->Groups, lookup, order); //fills group vectors from order vector. //fills group vectors from order vector.
158 //randomize group order
159 if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); }
162 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
163 for (int l = n; l < lookup.size(); l++) {
165 outputFileHandle << order->getLabel() << '\t';
167 //sort groups to be alphanumeric
168 if (lookup[k]->getGroup() > lookup[l]->getGroup()) {
169 outputFileHandle << (lookup[l]->getGroup() +'\t' + lookup[k]->getGroup()) << '\t'; //print out groups
171 outputFileHandle << (lookup[k]->getGroup() +'\t' + lookup[l]->getGroup()) << '\t'; //print out groups
174 for(int i=0;i<sumCalculators.size();i++){
175 sumCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs
176 outputFileHandle << '\t';
177 sumCalculators[i]->print(outputFileHandle);
179 outputFileHandle << endl;
185 //get next line to process
186 if (format == "sharedfile") {
187 order = input->getSharedOrderVector();
189 //you are using a list and a groupfile
190 SharedList = input->getSharedListVector(); //get new list vector to process
191 if (SharedList != NULL) {
192 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
200 //reset groups parameter
201 globaldata->Groups.clear(); globaldata->setGroups("");
205 catch(exception& e) {
206 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
210 cout << "An unknown error has occurred in the SummarySharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
215 /***********************************************************/