]> git.donarmstrong.com Git - mothur.git/blob - collectdisplay.h
sffinfo bug with flow grams right index when clipQualRight=0
[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                 vector<string> mGroups = m->getGroups();
35                 for (int i = 0; i < mGroups.size(); i++) {
36                         if (shared[0]->getGroup() == mGroups[i]) { group1Index = i; }
37                         if (shared[1]->getGroup() == mGroups[i]) { group2Index = i; }
38                 }
39                 
40                 numGroupComb = 0;
41                 int n = 1;
42                 for (int i = 0; i < (numGroups - 1); i++) {
43                         for (int l = n; l < numGroups; l++) {
44                                 if ((group1Index == i) && (group2Index == l)) {
45                                         pos = numGroupComb;  //pos tells you which column in the output file you are in
46                                 }else if ((group1Index == l) && (group2Index == i)) {
47                                         pos = numGroupComb;
48                                 }
49                                 numGroupComb++;
50                         }
51                         n++;
52                 }
53                         
54                 if ((estimate->getMultiple() == true) && all) { 
55                         numGroupComb++; 
56                         groupData.resize((numGroupComb*data.size()), 0);
57                         //is this the time its called with all values
58                         if  ((timesCalled % numGroupComb) == 0) { 
59                                 //last spot
60                                 pos = ((groupData.size()-1) * data.size());
61                         }
62                         //fills groupdata with datas info
63                         for (int i = 0; i < data.size(); i++) {
64                                 groupData[pos+i] = data[i];
65                         }
66                 }else {
67                         groupData.resize((numGroupComb*data.size()), 0);
68                         //fills groupdata with datas info
69                         for (int i = 0; i < data.size(); i++) {
70                                 groupData[pos+i] = data[i];
71                         }
72                 }
73                 
74                 //when you get all your groups info then output
75                 if ((timesCalled % numGroupComb) == 0) {
76                         output->output(numSeqs, groupData);     
77                 }
78         };
79                                                                         
80         void init(string s)             {       output->initFile(s);    };
81         void reset()                    {       output->resetFile();    };
82         void close()                    {       output->resetFile();    };
83         void setAll(bool a)             {       all = a;                                }
84         bool getAll()                   {       return all;                             }
85         
86         
87         bool isCalcMultiple()   { return estimate->getMultiple(); }
88         bool calcNeedsAll()     { return estimate->getNeedsAll(); }
89         bool hasLciHci()        {
90                 if (estimate->getCols() == 3) { return true; } 
91                 else{ return false; } 
92         }
93         
94         string getName()        {  return estimate->getName();  }
95         
96         
97 private:
98         
99         Calculator* estimate;
100         FileOutput* output;
101         int nSeqs, timesCalled, numGroupComb;
102         vector<double> data;
103         vector<double> groupData;
104         bool all;
105         
106 };
107
108 /***********************************************************************/
109
110 #endif