]> git.donarmstrong.com Git - mothur.git/blob - collectdisplay.h
bugs fixes while testing for 1.5 release
[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 /***********************************************************************/
12
13 class CollectDisplay : public Display {
14         
15 public:
16         CollectDisplay(Calculator* calc, FileOutput* file) : estimate(calc), output(file) {timesCalled = 0;};
17         ~CollectDisplay()       {       delete estimate; delete output;         }
18         void update(SAbundVector* rank){
19                 nSeqs=rank->getNumSeqs();
20                 data = estimate->getValues(rank);
21                 output->output(nSeqs, data);    
22         };
23         
24         void update(vector<SharedRAbundVector*> shared, int numSeqs, int numGroups){
25                 timesCalled++;
26                 data = estimate->getValues(shared);  //passes estimators a shared vector from each group to be compared
27                 
28                 //figure out what groups are being compared in getValues
29                 //because we randomizes the order we need to put the results in the correct column in the output file
30                 int group1Index, group2Index, pos;
31                 group1Index = shared[0]->getGroupIndex();
32                 group2Index = shared[1]->getGroupIndex();
33                 
34                 numGroupComb = 0;
35                 int n = 1;
36                 for (int i = 0; i < (numGroups - 1); i++) {
37                         for (int l = n; l < numGroups; l++) {
38                                 if ((group1Index == i) && (group2Index == l)) {
39                                         pos = numGroupComb;  //pos tells you which column in the output file you are in
40                                 }else if ((group1Index == l) && (group2Index == i)) {
41                                         pos = numGroupComb;
42                                 }
43                                 numGroupComb++;
44                         }
45                         n++;
46                 }
47                 
48                 if (estimate->getMultiple() == true) { 
49                         numGroupComb++; 
50                         groupData.resize((numGroupComb*data.size()), 0);
51                         //is this the time its called with all values
52                         if  ((timesCalled % numGroupComb) == 0) { 
53                                 //last spot
54                                 pos = ((groupData.size()-1) * data.size());
55                         }
56                         //fills groupdata with datas info
57                         for (int i = 0; i < data.size(); i++) {
58                                 groupData[pos+i] = data[i];
59                         }
60                 }else {
61                         groupData.resize((numGroupComb*data.size()), 0);
62                         //fills groupdata with datas info
63                         for (int i = 0; i < data.size(); i++) {
64                                 groupData[pos+i] = data[i];
65                         }
66                 }
67                 
68                 //when you get all your groups info then output
69                 if ((timesCalled % numGroupComb) == 0) {
70                         output->output(numSeqs, groupData);     
71                 }
72         };
73         
74         void init(string s)             {       output->initFile(s);    };
75         void reset()                    {       output->resetFile();    };
76         void close()                    {       output->resetFile();    };
77         bool isCalcMultiple() { return estimate->getMultiple(); }
78         
79         string getName()        {  return estimate->getName();  }
80
81 private:
82         
83         Calculator* estimate;
84         FileOutput* output;
85         int nSeqs, timesCalled, numGroupComb;
86         vector<double> data;
87         vector<double> groupData;
88 };
89
90 /***********************************************************************/
91
92 #endif