]> git.donarmstrong.com Git - mothur.git/blob - collectdisplay.h
af97c756d6a813959cabf5ce8f13f9e70f206806
[mothur.git] / collectdisplay.h
1 #ifndef COLLECTDISPLAY_H
2 #define COLLECTDISPLAY_H
3
4 #include "sabundvector.hpp"
5 #include "sharedsabundvector.h"
6 #include "calculator.h"
7 #include "fileoutput.h"
8 #include "display.h"
9
10
11 using namespace std;
12
13 /***********************************************************************/
14
15 class CollectDisplay : public Display {
16         
17 public:
18         CollectDisplay(Calculator* calc, FileOutput* file) : estimate(calc), output(file) {timesCalled = 0;};
19         ~CollectDisplay()       {       delete estimate; delete output;         }
20         void update(SAbundVector* rank){
21                 nSeqs=rank->getNumSeqs();
22                 data = estimate->getValues(rank);
23                 output->output(nSeqs, data);    
24         };
25         
26         void update(SharedRAbundVector* shared1, SharedRAbundVector* shared2, int numSeqs, int numGroups){
27                 timesCalled++;
28                 data = estimate->getValues(shared1, shared2);  //passes estimators a shared vector from each group to be compared
29                 
30                 //figure out what groups are being compared in getValues
31                 //because the jumble parameter randomizes the order we need to put the results in the correct column in the output file
32                 int group1Index, group2Index, pos;
33                 group1Index = shared1->getGroupIndex();
34                 group2Index = shared2->getGroupIndex();
35                 
36                 numGroupComb = 0;
37                 int n = 1;
38                 for (int i = 0; i < (numGroups - 1); i++) {
39                         for (int l = n; l < numGroups; l++) {
40                                 if ((group1Index == i) && (group2Index == l)) {
41                                         pos = numGroupComb;  //pos tells you which column in the output file you are in
42                                 }else if ((group1Index == l) && (group2Index == i)) {
43                                         pos = numGroupComb;
44                                 }
45                                 numGroupComb++;
46                         }
47                         n++;
48                 }
49
50                 groupData.resize((numGroupComb*data.size()), 0);
51                 
52                 //fills groupdata with datas info
53                 for (int i = 0; i < data.size(); i++) {
54                         groupData[pos+i] = data[i];
55                 }
56                 
57                 //when you get all your groups info then output
58                 if ((timesCalled % numGroupComb) == 0) {
59                         output->output(numSeqs, groupData);     
60                 }
61         };
62         
63         void init(string s)             {       output->initFile(s);    };
64         void reset()                    {       output->resetFile();    };
65         void close()                    {       output->resetFile();    };
66         
67 private:
68         Calculator* estimate;
69         FileOutput* output;
70         int nSeqs, timesCalled, numGroupComb;
71         vector<double> data;
72         vector<double> groupData;
73 };
74
75 /***********************************************************************/
76
77 #endif