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 "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"
23 //**********************************************************************************************************************
25 SummarySharedCommand::SummarySharedCommand(){
27 globaldata = GlobalData::getInstance();
28 outputFileName = ((getRootName(globaldata->inputFileName)) + "shared.summary");
29 openOutputFile(outputFileName, outputFileHandle);
30 format = globaldata->getFormat();
31 validCalculator = new ValidCalculators();
34 for (i=0; i<globaldata->Estimators.size(); i++) {
35 if (validCalculator->isValidCalculator("sharedsummary", globaldata->Estimators[i]) == true) {
36 if (globaldata->Estimators[i] == "sharedsobs") {
37 sumCalculators.push_back(new SharedSobsCS());
38 }else if (globaldata->Estimators[i] == "sharedchao") {
39 sumCalculators.push_back(new SharedChao1());
40 }else if (globaldata->Estimators[i] == "sharedace") {
41 sumCalculators.push_back(new SharedAce());
42 }else if (globaldata->Estimators[i] == "sharedjabund") {
43 sumCalculators.push_back(new SharedJAbund());
44 }else if (globaldata->Estimators[i] == "sharedsorensonabund") {
45 sumCalculators.push_back(new SharedSorAbund());
46 }else if (globaldata->Estimators[i] == "sharedjclass") {
47 sumCalculators.push_back(new SharedJclass());
48 }else if (globaldata->Estimators[i] == "sharedsorclass") {
49 sumCalculators.push_back(new SharedSorClass());
50 }else if (globaldata->Estimators[i] == "sharedjest") {
51 sumCalculators.push_back(new SharedJest());
52 }else if (globaldata->Estimators[i] == "sharedsorest") {
53 sumCalculators.push_back(new SharedSorEst());
54 }else if (globaldata->Estimators[i] == "sharedthetayc") {
55 sumCalculators.push_back(new SharedThetaYC());
56 }else if (globaldata->Estimators[i] == "sharedthetan") {
57 sumCalculators.push_back(new SharedThetaN());
62 //reset calc for next command
63 globaldata->setCalc("");
67 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
71 cout << "An unknown error has occurred in the SummarySharedCommand class function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
75 //**********************************************************************************************************************
77 SummarySharedCommand::~SummarySharedCommand(){
82 //**********************************************************************************************************************
84 int SummarySharedCommand::execute(){
88 //if the users entered no valid calculators don't execute command
89 if (sumCalculators.size() == 0) { return 0; }
91 if (format == "sharedfile") {
92 read = new ReadPhilFile(globaldata->inputFileName);
93 read->read(&*globaldata);
95 input = globaldata->ginput;
96 order = input->getSharedOrderVector();
98 //you are using a list and a groupfile
99 read = new ReadPhilFile(globaldata->inputFileName);
100 read->read(&*globaldata);
102 input = globaldata->ginput;
103 SharedList = globaldata->gSharedList;
104 order = SharedList->getSharedOrderVector();
107 //output estimator names as column headers
108 outputFileHandle << "label" <<'\t' << "comparison" << '\t';
109 for(int i=0;i<sumCalculators.size();i++){
110 outputFileHandle << '\t' << sumCalculators[i]->getName();
112 outputFileHandle << endl;
114 while(order != NULL){
116 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
118 cout << order->getLabel() << '\t' << count << endl;
119 getSharedVectors(); //fills group vectors from order vector.
121 //randomize group order
122 if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); }
125 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
126 for (int l = n; l < lookup.size(); l++) {
127 outputFileHandle << order->getLabel() << '\t' << (lookup[k]->getGroup() + lookup[l]->getGroup()) << '\t' << '\t'; //print out label and group
128 for(int i=0;i<sumCalculators.size();i++){
129 sumCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs
130 outputFileHandle << '\t';
131 sumCalculators[i]->print(outputFileHandle);
133 outputFileHandle << endl;
139 //get next line to process
140 if (format == "sharedfile") {
141 order = input->getSharedOrderVector();
143 //you are using a list and a groupfile
144 SharedList = input->getSharedListVector(); //get new list vector to process
145 if (SharedList != NULL) {
146 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
156 catch(exception& e) {
157 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
161 cout << "An unknown error has occurred in the SummarySharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
166 //**********************************************************************************************************************
168 void SummarySharedCommand::getSharedVectors(){
171 //create and initialize vector of sharedvectors, one for each group
172 for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) {
173 SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
174 temp->setLabel(order->getLabel());
175 temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
176 lookup.push_back(temp);
179 int numSeqs = order->size();
180 //sample all the members
181 for(int i=0;i<numSeqs;i++){
183 individual chosen = order->get(i);
186 //set info for sharedvector in chosens group
187 for (int j = 0; j < lookup.size(); j++) {
188 if (chosen.group == lookup[j]->getGroup()) {
189 abundance = lookup[j]->getAbundance(chosen.bin);
190 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
197 catch(exception& e) {
198 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
202 cout << "An unknown error has occurred in the SummarySharedCommand class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
208 //**********************************************************************************************************************