X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=raredisplay.cpp;h=b82127c51e6a64b50480a0f9b359cda3cd8e75f0;hb=70491a12902e89b85cfa6b44a7b7fbe066ee2ac1;hp=0b8030795f09e0ab774f4016101c646f516b49e4;hpb=d037597badc8d18e235c59f0c1114180edb7f98f;p=mothur.git diff --git a/raredisplay.cpp b/raredisplay.cpp index 0b80307..b82127c 100644 --- a/raredisplay.cpp +++ b/raredisplay.cpp @@ -14,20 +14,9 @@ void RareDisplay::init(string label){ try { this->label = label; - if(nIters != 1){ - openOutputFile(tempOutName, tempOutFile); - openInputFile(tempInName, tempInFile); - } - else{ - openOutputFile(tempOutName, tempOutFile); - } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function init. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the RareDisplay class function init. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "RareDisplay", "init"); exit(1); } } @@ -41,88 +30,72 @@ void RareDisplay::update(SAbundVector* rank){ if(nIters != 1){ - double oldNSeqs, oldMean, oldVar; - - tempInFile >> oldNSeqs >> oldMean >> oldVar; - - double oldS = oldVar * ( nIters - 2 ); - double delta = data[0] - oldMean; - double newMean = oldMean + delta / nIters; + double oldS = var[index] * ( nIters - 2 ); + double delta = data[0] - results[index]; + double newMean = results[index] + delta / nIters; double newS = oldS + delta * ( data[0] - newMean ); double newVar = newS / ( nIters - 1 ); - tempOutFile << newNSeqs << '\t' << newMean << '\t' << newVar << endl; + seqs[index] = newNSeqs; + results[index] = newMean; + var[index] = newVar; + + index++; } else{ - tempOutFile << newNSeqs << '\t' << data[0] << '\t' << 0 << endl; + seqs.push_back(newNSeqs); + results.push_back(data[0]); + var.push_back(0.0); } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "RareDisplay", "update"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the RareDisplay class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -}; +} /***********************************************************************/ -void RareDisplay::update(SharedRAbundVector* shared1, SharedRAbundVector* shared2, int numSeqs, int numGroupComb) { +void RareDisplay::update(vector shared, int numSeqs, int numGroupComb) { try { - vector data = estimate->getValues(shared1, shared2); + vector data = estimate->getValues(shared); double newNSeqs = data[0]; if(nIters != 1){ - double oldNSeqs, oldMean, oldVar; - - tempInFile >> oldNSeqs >> oldMean >> oldVar; - double oldS = oldVar * ( nIters - 2 ); - double delta = data[0] - oldMean; - double newMean = oldMean + delta / nIters; + double oldS = var[index] * ( nIters - 2 ); + double delta = data[0] - results[index]; + double newMean = results[index] + delta / nIters; double newS = oldS + delta * ( data[0] - newMean ); double newVar = newS / ( nIters - 1 ); - - tempOutFile << newNSeqs << '\t' << newMean << '\t' << newVar << endl; + seqs[index] = newNSeqs; + results[index] = newMean; + var[index] = newVar; + + index++; } else{ - tempOutFile << newNSeqs << '\t' << data[0] << '\t' << 0 << endl; + + seqs.push_back(newNSeqs); + results.push_back(data[0]); + var.push_back(0.0); + } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the RareDisplay class function update. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "RareDisplay", "update"); exit(1); } -}; +} /***********************************************************************/ void RareDisplay::reset(){ try { - if(nIters != 1){ - tempOutFile.close(); - tempInFile.close(); - } - else{ - tempOutFile.close(); - } - nIters++; - - remove(tempInName.c_str()); - rename(tempOutName.c_str(), tempInName.c_str()); + index = 0; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the RareDisplay class function reset. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "RareDisplay", "reset"); exit(1); } } @@ -131,45 +104,86 @@ void RareDisplay::reset(){ void RareDisplay::close(){ try { + output->initFile(label); - openInputFile(tempInName, tempInFile); - - while(!tempInFile.eof()){ - int nSeqs; - tempInFile >> nSeqs; + for (int i = 0; i < seqs.size(); i++) { vector data(3,0); - double variance = 0; - - tempInFile >> data[0]; - tempInFile >> variance; - + double variance = var[i]; + + data[0] = results[i]; + double ci = 1.96 * pow(variance, 0.5); data[1] = data[0] - ci; data[2] = data[0] + ci; - output->output(nSeqs, data); - - gobble(tempInFile); + output->output(seqs[i], data); } - tempInFile.close(); - - remove(tempInName.c_str()); - remove(tempOutName.c_str()); - + nIters = 1; + index = 0; + + seqs.clear(); + results.clear(); + var.clear(); + output->resetFile(); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the RareDisplay class Function close. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "RareDisplay", "close"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the RareDisplay class function close. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} +/***********************************************************************/ + +void RareDisplay::inputTempFiles(string filename){ + try { + ifstream in; + m->openInputFile(filename, in); + + int thisIters; + in >> thisIters; m->gobble(in); + + for (int i = 0; i < seqs.size(); i++) { + double tempresult, tempvar; + in >> tempresult >> tempvar; m->gobble(in); + + //find weighted result + results[i] = ((nIters * results[i]) + (thisIters * tempresult)) / (float)(nIters + thisIters); + + var[i] = ((nIters * var[i]) + (thisIters * tempvar)) / (float)(nIters + thisIters); + } + + in.close(); + } + catch(exception& e) { + m->errorOut(e, "RareDisplay", "inputTempFiles"); exit(1); } } /***********************************************************************/ +void RareDisplay::outputTempFiles(string filename){ + try { + ofstream out; + m->openOutputFile(filename, out); + + out << nIters << endl; + + for (int i = 0; i < seqs.size(); i++) { + out << results[i] << '\t' << var[i] << endl; + } + + out.close(); + } + catch(exception& e) { + m->errorOut(e, "RareDisplay", "outputTempFiles"); + exit(1); + } +} + + +/***********************************************************************/ +