]> git.donarmstrong.com Git - mothur.git/blob - collectdisplay.h
added concensus command and updated calcs
[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(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 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 = shared[0]->getGroupIndex();
34                 group2Index = shared[1]->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                 if (estimate->getMultiple() == true) { 
51                         numGroupComb++; 
52                         groupData.resize((numGroupComb*data.size()), 0);
53                         //is this the time its called with all values
54                         if  ((timesCalled % numGroupComb) == 0) { 
55                                 //last spot
56                                 pos = ((groupData.size()-1) * data.size());
57                         }
58                         //fills groupdata with datas info
59                         for (int i = 0; i < data.size(); i++) {
60                                 groupData[pos+i] = data[i];
61                         }
62                 }else {
63                         groupData.resize((numGroupComb*data.size()), 0);
64                         //fills groupdata with datas info
65                         for (int i = 0; i < data.size(); i++) {
66                                 groupData[pos+i] = data[i];
67                         }
68                 }
69                 
70                 //when you get all your groups info then output
71                 if ((timesCalled % numGroupComb) == 0) {
72                         output->output(numSeqs, groupData);     
73                 }
74         };
75         
76         void init(string s)             {       output->initFile(s);    };
77         void reset()                    {       output->resetFile();    };
78         void close()                    {       output->resetFile();    };
79         bool isCalcMultiple() { return estimate->getMultiple(); }
80         
81 private:
82         Calculator* estimate;
83         FileOutput* output;
84         int nSeqs, timesCalled, numGroupComb;
85         vector<double> data;
86         vector<double> groupData;
87 };
88
89 /***********************************************************************/
90
91 #endif