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 renameOk = rename(tempOutName.c_str(), tempInName.c_str());
120 //checks to make sure user was able to rename and remove successfully
121 if (renameOk != 0) { cout << "Unable to rename the necessary temp files." << endl; }
123 catch(exception& e) {
124 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
128 cout << "An unknown error has occurred in the RareDisplay class function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
133 /***********************************************************************/
135 void RareDisplay::close(){
137 output->initFile(label);
139 openInputFile(tempInName, tempInFile);
141 while(!tempInFile.eof()){
145 vector<double> data(3,0);
148 tempInFile >> data[0];
149 tempInFile >> variance;
151 double ci = 1.96 * pow(variance, 0.5);
152 data[1] = data[0] - ci;
153 data[2] = data[0] + ci;
155 output->output(nSeqs, data);
161 remove(tempInName.c_str());
162 remove(tempOutName.c_str());
167 catch(exception& e) {
168 cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function close. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
172 cout << "An unknown error has occurred in the RareDisplay class function close. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
177 /***********************************************************************/