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 "sharedchao1.h"
12 #include "sharedace.h"
13 #include "sharedjabund.h"
14 #include "sharedsorabund.h"
15 #include "sharedjclass.h"
16 #include "sharedsorclass.h"
17 #include "sharedjest.h"
18 #include "sharedsorest.h"
19 #include "sharedthetayc.h"
20 #include "sharedthetan.h"
22 //**********************************************************************************************************************
24 SummarySharedCommand::SummarySharedCommand(){
26 globaldata = GlobalData::getInstance();
29 for (i=0; i<globaldata->sharedSummaryEstimators.size(); i++) {
30 if (globaldata->sharedSummaryEstimators[i] == "sharedChao") {
31 sumCalculators.push_back(new SharedChao1());
32 }else if (globaldata->sharedSummaryEstimators[i] == "sharedAce") {
33 sumCalculators.push_back(new SharedAce());
34 }else if (globaldata->sharedSummaryEstimators[i] == "sharedJabund") {
35 sumCalculators.push_back(new SharedJAbund());
36 }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorensonAbund") {
37 sumCalculators.push_back(new SharedSorAbund());
38 }else if (globaldata->sharedSummaryEstimators[i] == "sharedJclass") {
39 sumCalculators.push_back(new SharedJclass());
40 }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorClass") {
41 sumCalculators.push_back(new SharedSorClass());
42 }else if (globaldata->sharedSummaryEstimators[i] == "sharedJest") {
43 sumCalculators.push_back(new SharedJest());
44 }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorEst") {
45 sumCalculators.push_back(new SharedSorEst());
46 }else if (globaldata->sharedSummaryEstimators[i] == "SharedThetaYC") {
47 sumCalculators.push_back(new SharedThetaYC());
48 }else if (globaldata->sharedSummaryEstimators[i] == "SharedThetaN") {
49 sumCalculators.push_back(new SharedThetaN());
54 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
58 cout << "An unknown error has occurred in the SummarySharedCommand class function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62 //**********************************************************************************************************************
64 SummarySharedCommand::~SummarySharedCommand(){
69 //**********************************************************************************************************************
71 int SummarySharedCommand::execute(){
73 outputFileName = ((getRootName(globaldata->inputFileName)) + "sharedSummary");
74 openOutputFile(outputFileName, outputFileHandle);
76 read = new ReadPhilFile(globaldata->inputFileName);
77 read->read(&*globaldata);
79 outputFileHandle << '\t' << '\t' << '\t' << '\t'; //pads file for labels and groupnames
80 for(int i=0;i<sumCalculators.size();i++){
81 outputFileHandle << '\t' << sumCalculators[i]->getName();
83 outputFileHandle << endl;
85 list = globaldata->glist;
86 input = globaldata->ginput;
87 order = list->getSharedOrderVector();
93 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
95 cout << order->getLabel() << '\t' << count << endl;
96 getSharedVectors(); //fills group vectors from order vector.
98 //randomize group order
99 if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); }
102 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
103 for (int l = n; l < lookup.size(); l++) {
104 outputFileHandle << order->getLabel() << '\t' << groupComb[n-1] << '\t'; //print out label and group
105 for(int i=0;i<sumCalculators.size();i++){
106 sumCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs
107 outputFileHandle << '\t';
108 sumCalculators[i]->print(outputFileHandle);
110 outputFileHandle << endl;
116 list = input->getListVector(); //get new list vector to process
118 order = list->getSharedOrderVector(); //gets new order vector with group info.
127 catch(exception& e) {
128 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
132 cout << "An unknown error has occurred in the SummarySharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
137 //**********************************************************************************************************************
139 void SummarySharedCommand::getSharedVectors(){
142 //create and initialize vector of sharedvectors, one for each group
143 for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) {
144 SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
145 temp->setLabel(order->getLabel());
146 temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
147 lookup.push_back(temp);
150 int numSeqs = order->size();
151 //sample all the members
152 for(int i=0;i<numSeqs;i++){
154 individual chosen = order->get(i);
157 //set info for sharedvector in chosens group
158 for (int j = 0; j < lookup.size(); j++) {
159 if (chosen.group == lookup[j]->getGroup()) {
160 abundance = lookup[j]->getAbundance(chosen.bin);
161 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
168 catch(exception& e) {
169 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
173 cout << "An unknown error has occurred in the SummarySharedCommand class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
179 /**************************************************************************************/
180 void SummarySharedCommand::getGroupComb() {
185 for (int i = 0; i < (globaldata->gGroupmap->getNumGroups() - 1); i++) {
186 for (int l = n; l < globaldata->gGroupmap->getNumGroups(); l++) {
187 group = globaldata->gGroupmap->namesOfGroups[i] + globaldata->gGroupmap->namesOfGroups[l];
188 groupComb.push_back(group);
193 catch(exception& e) {
194 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function getGroupComb. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
198 cout << "An unknown error has occurred in the SummarySharedCommand class function getGroupComb. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";