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();
30 for (i=0; i<globaldata->sharedSummaryEstimators.size(); i++) {
31 if (globaldata->sharedSummaryEstimators[i] == "sharedSobs") {
32 sumCalculators.push_back(new SharedSobsCS());
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();
95 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
97 cout << order->getLabel() << '\t' << count << endl;
98 getSharedVectors(); //fills group vectors from order vector.
100 //randomize group order
101 if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); }
104 for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare
105 for (int l = n; l < lookup.size(); l++) {
106 outputFileHandle << order->getLabel() << '\t' << (lookup[k]->getGroup() + lookup[l]->getGroup()) << '\t' << '\t'; //print out label and group
107 for(int i=0;i<sumCalculators.size();i++){
108 sumCalculators[i]->getValues(lookup[k], lookup[l]); //saves the calculator outputs
109 outputFileHandle << '\t';
110 sumCalculators[i]->print(outputFileHandle);
112 outputFileHandle << endl;
118 SharedList = input->getSharedListVector(); //get new list vector to process
119 if (SharedList != NULL) {
120 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
129 catch(exception& e) {
130 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
134 cout << "An unknown error has occurred in the SummarySharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
139 //**********************************************************************************************************************
141 void SummarySharedCommand::getSharedVectors(){
144 //create and initialize vector of sharedvectors, one for each group
145 for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) {
146 SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
147 temp->setLabel(order->getLabel());
148 temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]);
149 lookup.push_back(temp);
152 int numSeqs = order->size();
153 //sample all the members
154 for(int i=0;i<numSeqs;i++){
156 individual chosen = order->get(i);
159 //set info for sharedvector in chosens group
160 for (int j = 0; j < lookup.size(); j++) {
161 if (chosen.group == lookup[j]->getGroup()) {
162 abundance = lookup[j]->getAbundance(chosen.bin);
163 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
170 catch(exception& e) {
171 cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
175 cout << "An unknown error has occurred in the SummarySharedCommand class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
181 //**********************************************************************************************************************