5 * Created by Sarah Westcott on 11/18/08.
6 * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "raredisplay.h"
12 /***********************************************************************/
14 void RareDisplay::init(string label){
19 openOutputFile(tempOutName, tempOutFile);
20 openInputFile(tempInName, tempInFile);
23 openOutputFile(tempOutName, tempOutFile);
27 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function init. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
31 cout << "An unknown error has occurred in the RareDisplay class function init. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
36 /***********************************************************************/
38 void RareDisplay::update(SAbundVector* rank){
40 int newNSeqs = rank->getNumSeqs();
41 vector<double> data = estimate->getValues(rank);
45 double oldNSeqs, oldMean, oldVar;
47 tempInFile >> oldNSeqs >> oldMean >> oldVar;
49 double oldS = oldVar * ( nIters - 2 );
50 double delta = data[0] - oldMean;
51 double newMean = oldMean + delta / nIters;
52 double newS = oldS + delta * ( data[0] - newMean );
53 double newVar = newS / ( nIters - 1 );
55 tempOutFile << newNSeqs << '\t' << newMean << '\t' << newVar << endl;
58 tempOutFile << newNSeqs << '\t' << data[0] << '\t' << 0 << endl;
62 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
66 cout << "An unknown error has occurred in the RareDisplay class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
71 /***********************************************************************/
72 void RareDisplay::update(vector<SharedRAbundVector*> shared, int numSeqs, int numGroupComb) {
74 vector<double> data = estimate->getValues(shared);
75 double newNSeqs = data[0];
78 double oldNSeqs, oldMean, oldVar;
80 tempInFile >> oldNSeqs >> oldMean >> oldVar;
82 double oldS = oldVar * ( nIters - 2 );
83 double delta = data[0] - oldMean;
84 double newMean = oldMean + delta / nIters;
85 double newS = oldS + delta * ( data[0] - newMean );
86 double newVar = newS / ( nIters - 1 );
88 tempOutFile << newNSeqs << '\t' << newMean << '\t' << newVar << endl;
91 tempOutFile << newNSeqs << '\t' << data[0] << '\t' << 0 << endl;
95 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
99 cout << "An unknown error has occurred in the RareDisplay class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
104 /***********************************************************************/
106 void RareDisplay::reset(){
118 remove(tempInName.c_str());
119 renameOk = rename(tempOutName.c_str(), tempInName.c_str());
121 //checks to make sure user was able to rename and remove successfully
122 if (renameOk != 0) { cout << "Unable to rename the necessary temp files." << endl; }
124 catch(exception& e) {
125 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
129 cout << "An unknown error has occurred in the RareDisplay class function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
134 /***********************************************************************/
136 void RareDisplay::close(){
139 output->initFile(label);
141 openInputFile(tempInName, tempInFile);
143 while(!tempInFile.eof()){
147 vector<double> data(3,0);
150 tempInFile >> data[0];
151 tempInFile >> variance;
153 double ci = 1.96 * pow(variance, 0.5);
154 data[1] = data[0] - ci;
155 data[2] = data[0] + ci;
157 output->output(nSeqs, data);
163 remove(tempInName.c_str());
164 remove(tempOutName.c_str());
169 catch(exception& e) {
170 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function close. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
174 cout << "An unknown error has occurred in the RareDisplay class function close. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
179 /***********************************************************************/