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 m->errorOut(e, "RareDisplay", "init");
24 /***********************************************************************/
26 void RareDisplay::update(SAbundVector* rank){
28 int newNSeqs = rank->getNumSeqs();
29 vector<double> data = estimate->getValues(rank);
31 map<int, vector<double> >::iterator it = results.find(newNSeqs);
32 if (it == results.end()) { //first iter for this count
34 temp.push_back(data[0]);
35 results[newNSeqs] = temp;
37 it->second.push_back(data[0]);
41 m->errorOut(e, "RareDisplay", "update");
46 /***********************************************************************/
47 void RareDisplay::update(vector<SharedRAbundVector*> shared, int numSeqs, int numGroupComb) {
49 vector<double> data = estimate->getValues(shared);
51 map<int, vector<double> >::iterator it = results.find(numSeqs);
52 if (it == results.end()) { //first iter for this count
54 temp.push_back(data[0]);
55 results[numSeqs] = temp;
57 it->second.push_back(data[0]);
61 m->errorOut(e, "RareDisplay", "update");
66 /***********************************************************************/
68 void RareDisplay::reset(){
73 m->errorOut(e, "RareDisplay", "reset");
78 /***********************************************************************/
80 void RareDisplay::close(){
82 output->initFile(label);
84 for (map<int, vector<double> >::iterator it = results.begin(); it != results.end(); it++) {
86 vector<double> data(3,0);
88 sort((it->second).begin(), (it->second).end());
90 //lci=results[int(0.025*iter)] and hci=results[int(0.975*iter)]
91 data[0] = (it->second)[(int)(0.50*(nIters-1))];
92 //data[0] = m->getAverage(it->second);
93 data[1] = (it->second)[(int)(0.025*(nIters-1))];
94 data[2] = (it->second)[(int)(0.975*(nIters-1))];
95 //cout << nIters << '\t' << (int)(0.025*(nIters-1)) << '\t' << (int)(0.975*(nIters-1)) << endl;
97 //cout << it->first << '\t' << data[1] << '\t' << data[2] << endl;
99 output->output(it->first, data);
107 catch(exception& e) {
108 m->errorOut(e, "RareDisplay", "close");
112 /***********************************************************************/
114 void RareDisplay::inputTempFiles(string filename){
117 m->openInputFile(filename, in);
120 in >> thisIters >> size; m->gobble(in);
123 for (int i = 0; i < size; i++) {
125 in >> tempCount; m->gobble(in);
126 map<int, vector<double> >::iterator it = results.find(tempCount);
127 if (it != results.end()) {
128 for (int j = 0; j < thisIters; j++) {
130 in >> value; m->gobble(in);
131 (it->second).push_back(value);
134 vector<double> tempValues;
135 for (int j = 0; j < thisIters; j++) {
137 in >> value; m->gobble(in);
138 tempValues.push_back(value);
140 results[tempCount] = tempValues;
146 catch(exception& e) {
147 m->errorOut(e, "RareDisplay", "inputTempFiles");
152 /***********************************************************************/
154 void RareDisplay::outputTempFiles(string filename){
157 m->openOutputFile(filename, out);
159 out << nIters-1 << '\t' << results.size() << endl;
161 for (map<int, vector<double> >::iterator it = results.begin(); it != results.end(); it++) {
162 out << it->first << '\t';
163 for(int i = 0; i < (it->second).size(); i++) {
164 out << (it->second)[i] << '\t';
171 catch(exception& e) {
172 m->errorOut(e, "RareDisplay", "outputTempFiles");
178 /***********************************************************************/