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