]> git.donarmstrong.com Git - mothur.git/blob - collectdisplay.h
fixed bug with trim.seqs- when a file is blank for a grouping mothur removed it,...
[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                 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) && all) { 
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         void setAll(bool a)             {       all = a;                                }
80         bool getAll()                   {       return all;                             }
81         
82         
83         bool isCalcMultiple()   { return estimate->getMultiple(); }
84         bool calcNeedsAll()     { return estimate->getNeedsAll(); }
85         bool hasLciHci()        {
86                 if (estimate->getCols() == 3) { return true; } 
87                 else{ return false; } 
88         }
89         
90         string getName()        {  return estimate->getName();  }
91         
92         
93 private:
94         
95         Calculator* estimate;
96         FileOutput* output;
97         int nSeqs, timesCalled, numGroupComb;
98         vector<double> data;
99         vector<double> groupData;
100         bool all;
101         
102 };
103
104 /***********************************************************************/
105
106 #endif