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){
18 openOutputFile(tempOutName, tempOutFile);
19 openInputFile(tempInName, tempInFile);
22 openOutputFile(tempOutName, tempOutFile);
26 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function init. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
30 cout << "An unknown error has occurred in the RareDisplay class function init. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
35 /***********************************************************************/
37 void RareDisplay::update(SAbundVector* rank){
39 int newNSeqs = rank->getNumSeqs();
40 vector<double> data = estimate->getValues(rank);
44 double oldNSeqs, oldMean, oldVar;
46 tempInFile >> oldNSeqs >> oldMean >> oldVar;
48 double oldS = oldVar * ( nIters - 2 );
49 double delta = data[0] - oldMean;
50 double newMean = oldMean + delta / nIters;
51 double newS = oldS + delta * ( data[0] - newMean );
52 double newVar = newS / ( nIters - 1 );
54 tempOutFile << newNSeqs << '\t' << newMean << '\t' << newVar << endl;
57 tempOutFile << newNSeqs << '\t' << data[0] << '\t' << 0 << endl;
61 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
65 cout << "An unknown error has occurred in the RareDisplay class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
70 /***********************************************************************/
71 void RareDisplay::update(SharedRAbundVector* shared1, SharedRAbundVector* shared2, int numSeqs, int numGroupComb) {
73 vector<double> data = estimate->getValues(shared1, shared2);
74 double newNSeqs = data[0];
77 double oldNSeqs, oldMean, oldVar;
79 tempInFile >> oldNSeqs >> oldMean >> oldVar;
81 double oldS = oldVar * ( nIters - 2 );
82 double delta = data[0] - oldMean;
83 double newMean = oldMean + delta / nIters;
84 double newS = oldS + delta * ( data[0] - newMean );
85 double newVar = newS / ( nIters - 1 );
87 tempOutFile << newNSeqs << '\t' << newMean << '\t' << newVar << endl;
90 tempOutFile << newNSeqs << '\t' << data[0] << '\t' << 0 << endl;
94 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
98 cout << "An unknown error has occurred in the RareDisplay class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
103 /***********************************************************************/
105 void RareDisplay::reset(){
117 remove(tempInName.c_str());
118 rename(tempOutName.c_str(), tempInName.c_str());
120 catch(exception& e) {
121 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
125 cout << "An unknown error has occurred in the RareDisplay class function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
130 /***********************************************************************/
132 void RareDisplay::close(){
134 output->initFile(label);
136 openInputFile(tempInName, tempInFile);
138 while(!tempInFile.eof()){
142 vector<double> data(3,0);
145 tempInFile >> data[0];
146 tempInFile >> variance;
148 double ci = 1.96 * pow(variance, 0.5);
149 data[1] = data[0] - ci;
150 data[2] = data[0] + ci;
152 output->output(nSeqs, data);
158 remove(tempInName.c_str());
159 remove(tempOutName.c_str());
164 catch(exception& e) {
165 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function close. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
169 cout << "An unknown error has occurred in the RareDisplay class function close. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
174 /***********************************************************************/