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 "sharedsobs.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();
30 for (i=0; i<globaldata->sharedSummaryEstimators.size(); i++) {
31 if (globaldata->sharedSummaryEstimators[i] == "sharedSobs") {
32 sumCalculators.push_back(new SharedSobs());
33 }else if (globaldata->sharedSummaryEstimators[i] == "sharedChao") {
34 sumCalculators.push_back(new SharedChao1());
35 }else if (globaldata->sharedSummaryEstimators[i] == "sharedAce") {
36 sumCalculators.push_back(new SharedAce());
37 }else if (globaldata->sharedSummaryEstimators[i] == "sharedJabund") {
38 sumCalculators.push_back(new SharedJAbund());
39 }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorensonAbund") {
40 sumCalculators.push_back(new SharedSorAbund());
41 }else if (globaldata->sharedSummaryEstimators[i] == "sharedJclass") {
42 sumCalculators.push_back(new SharedJclass());
43 }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorClass") {
44 sumCalculators.push_back(new SharedSorClass());
45 }else if (globaldata->sharedSummaryEstimators[i] == "sharedJest") {
46 sumCalculators.push_back(new SharedJest());
47 }else if (globaldata->sharedSummaryEstimators[i] == "sharedSorEst") {
48 sumCalculators.push_back(new SharedSorEst());
49 }else if (globaldata->sharedSummaryEstimators[i] == "SharedThetaYC") {
50 sumCalculators.push_back(new SharedThetaYC());
51 }else if (globaldata->sharedSummaryEstimators[i] == "SharedThetaN") {
52 sumCalculators.push_back(new SharedThetaN());
57 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
61 cout << "An unknown error has occurred in the SummarySharedCommand class function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
65 //**********************************************************************************************************************
67 SummarySharedCommand::~SummarySharedCommand(){
72 //**********************************************************************************************************************
74 int SummarySharedCommand::execute(){
76 outputFileName = ((getRootName(globaldata->inputFileName)) + "shared.summary");
77 openOutputFile(outputFileName, outputFileHandle);
79 read = new ReadPhilFile(globaldata->inputFileName);
80 read->read(&*globaldata);
82 outputFileHandle << "label" <<'\t' << "comparison" << '\t';
83 for(int i=0;i<sumCalculators.size();i++){
84 outputFileHandle << '\t' << sumCalculators[i]->getName();
86 outputFileHandle << endl;
88 SharedList = globaldata->gSharedList;
89 input = globaldata->ginput;
90 order = SharedList->getSharedOrderVector();
96 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
98 cout << order->getLabel() << '\t' << count << endl;
99 getSharedVectors(); //fills group vectors from order vector.
101 //randomize group order
102 if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); }
105 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
106 for (int l = n; l < lookup.size(); l++) {
107 outputFileHandle << order->getLabel() << '\t' << groupComb[n-1] << '\t' << '\t'; //print out label and group
108 for(int i=0;i<sumCalculators.size();i++){
109 sumCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs
110 outputFileHandle << '\t';
111 sumCalculators[i]->print(outputFileHandle);
113 outputFileHandle << endl;
119 SharedList = input->getSharedListVector(); //get new list vector to process
120 if (SharedList != NULL) {
121 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
130 catch(exception& e) {
131 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
135 cout << "An unknown error has occurred in the SummarySharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
140 //**********************************************************************************************************************
142 void SummarySharedCommand::getSharedVectors(){
145 //create and initialize vector of sharedvectors, one for each group
146 for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) {
147 SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
148 temp->setLabel(order->getLabel());
149 temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
150 lookup.push_back(temp);
153 int numSeqs = order->size();
154 //sample all the members
155 for(int i=0;i<numSeqs;i++){
157 individual chosen = order->get(i);
160 //set info for sharedvector in chosens group
161 for (int j = 0; j < lookup.size(); j++) {
162 if (chosen.group == lookup[j]->getGroup()) {
163 abundance = lookup[j]->getAbundance(chosen.bin);
164 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
171 catch(exception& e) {
172 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
176 cout << "An unknown error has occurred in the SummarySharedCommand class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
182 /**************************************************************************************/
183 void SummarySharedCommand::getGroupComb() {
188 for (int i = 0; i < (globaldata->gGroupmap->getNumGroups() - 1); i++) {
189 for (int l = n; l < globaldata->gGroupmap->getNumGroups(); l++) {
190 group = globaldata->gGroupmap->namesOfGroups[i] + globaldata->gGroupmap->namesOfGroups[l];
191 groupComb.push_back(group);
196 catch(exception& e) {
197 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function getGroupComb. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
201 cout << "An unknown error has occurred in the SummarySharedCommand class function getGroupComb. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";