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] == "sharedjabund") {
55 sumCalculators.push_back(new SharedJAbund());
56 }else if (globaldata->Estimators[i] == "sharedsorensonabund") {
57 sumCalculators.push_back(new SharedSorAbund());
58 }else if (globaldata->Estimators[i] == "sharedjclass") {
59 sumCalculators.push_back(new SharedJclass());
60 }else if (globaldata->Estimators[i] == "sharedsorclass") {
61 sumCalculators.push_back(new SharedSorClass());
62 }else if (globaldata->Estimators[i] == "sharedjest") {
63 sumCalculators.push_back(new SharedJest());
64 }else if (globaldata->Estimators[i] == "sharedsorest") {
65 sumCalculators.push_back(new SharedSorEst());
66 }else if (globaldata->Estimators[i] == "sharedthetayc") {
67 sumCalculators.push_back(new SharedThetaYC());
68 }else if (globaldata->Estimators[i] == "sharedthetan") {
69 sumCalculators.push_back(new SharedThetaN());
70 }else if (globaldata->Estimators[i] == "sharedkstest") {
71 sumCalculators.push_back(new SharedKSTest());
72 }else if (globaldata->Estimators[i] == "sharednseqs") {
73 sumCalculators.push_back(new SharedNSeqs());
74 }else if (globaldata->Estimators[i] == "sharedochiai") {
75 sumCalculators.push_back(new SharedOchiai());
76 }else if (globaldata->Estimators[i] == "sharedanderberg") {
77 sumCalculators.push_back(new SharedAnderberg());
78 }else if (globaldata->Estimators[i] == "sharedkulczynski") {
79 sumCalculators.push_back(new SharedKulczynski());
80 }else if (globaldata->Estimators[i] == "sharedkulczynskicody") {
81 sumCalculators.push_back(new SharedKulczynskiCody());
82 }else if (globaldata->Estimators[i] == "sharedlennon") {
83 sumCalculators.push_back(new SharedLennon());
84 }else if (globaldata->Estimators[i] == "sharedmorisitahorn") {
85 sumCalculators.push_back(new SharedMorHorn());
86 }else if (globaldata->Estimators[i] == "sharedbraycurtis") {
87 sumCalculators.push_back(new SharedBrayCurtis());
89 else if (globaldata->Estimators[i] == "sharedbdiversity") {
90 sumCalculators.push_back(new SharedBDiversity());
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 ReadPhilFile(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 ReadPhilFile(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 /***********************************************************/