File: raredisplay.cpp

package info (click to toggle)
mothur 1.48.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,692 kB
  • sloc: cpp: 161,866; makefile: 122; sh: 31
file content (115 lines) | stat: -rwxr-xr-x 2,940 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 *  raredisplay.cpp
 *  Dotur
 *
 *  Created by Sarah Westcott on 11/18/08.
 *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
 *
 */

#include "raredisplay.h"

/***********************************************************************/

void RareDisplay::init(string label){
	try {
        lock_guard<std::mutex> guard(mutex);
		this->label = label;
	}
	catch(exception& e) {
		m->errorOut(e, "RareDisplay", "init");
		exit(1);
	}
}

/***********************************************************************/

void RareDisplay::update(SAbundVector& rank){
	try {
        lock_guard<std::mutex> guard(mutex);
        
		int newNSeqs = rank.getNumSeqs();
		vector<double> data = estimate->getValues(&rank);

		map<int, vector<double> >::iterator it = results.find(newNSeqs);
        if (it == results.end()) { //first iter for this count
            vector<double> temp;
            temp.push_back(data[0]);
            results[newNSeqs] = temp;
        }else {
            it->second.push_back(data[0]);
        }
	}
	catch(exception& e) {
		m->errorOut(e, "RareDisplay", "update");
		exit(1);
	}
}

/***********************************************************************/
void RareDisplay::update(vector<SharedRAbundVector*> shared, int numSeqs) {
	try {
        lock_guard<std::mutex> guard(mutex);
        
		vector<double> data = estimate->getValues(shared);
		
		map<int, vector<double> >::iterator it = results.find(numSeqs);
        if (it == results.end()) { //first iter for this count
            vector<double> temp;
            temp.push_back(data[0]);
            results[numSeqs] = temp;
        }else {
            it->second.push_back(data[0]);
        }
	}
	catch(exception& e) {
		m->errorOut(e, "RareDisplay", "update");
		exit(1);
	}
}

/***********************************************************************/

void RareDisplay::reset(){
	try {
        lock_guard<std::mutex> guard(mutex);
		nIters++;
	}
	catch(exception& e) {
		m->errorOut(e, "RareDisplay", "reset");
		exit(1);
	}
}

/***********************************************************************/
//assumes only one thread will run close
void RareDisplay::close(){
	try {
		output->setLabelName(label);
	
		for (map<int, vector<double> >::iterator it = results.begin(); it != results.end(); it++) {
		
			vector<double> data(3,0);
            
            sort((it->second).begin(), (it->second).end());
            
            vector<double> thisResults = it->second;
            double meanResults = util.getAverage(thisResults);
			data[0] = meanResults;
			data[1] = (it->second)[(int)(0.025*(nIters-1))];
			data[2] = (it->second)[(int)(0.975*(nIters-1))];
		
			output->updateOutput(it->first, data);
		}
		
		nIters = 1;
        results.clear();
		
		output->resetFile();
	}
	catch(exception& e) {
		m->errorOut(e, "RareDisplay", "close");
		exit(1);
	}
}
/***********************************************************************/