]> git.donarmstrong.com Git - mothur.git/blobdiff - collectdisplay.h
bugs fixes while testing for 1.5 release
[mothur.git] / collectdisplay.h
index 367a188dfb8de90c2e464cb70cc4a7b1b826ccfe..0f18da6277853059464b1902aeb81b92a3facae1 100644 (file)
@@ -6,9 +6,7 @@
 #include "calculator.h"
 #include "fileoutput.h"
 #include "display.h"
-#include <vector>
 
-using namespace std;
 
 /***********************************************************************/
 
@@ -23,28 +21,68 @@ public:
                output->output(nSeqs, data);    
        };
        
-       void update(SharedRAbundVector* shared1, SharedRAbundVector* shared2, int numSeqs, int numGroupComb){
+       void update(vector<SharedRAbundVector*> shared, int numSeqs, int numGroups){
                timesCalled++;
-               data = estimate->getValues(shared1, shared2);  //passes estimators a shared vector from each group to be compared
-               //fills groupdata with datas info
-               for (int i = 0; i < data.size(); i++) {
-                       groupData.push_back(data[i]);
+               data = estimate->getValues(shared);  //passes estimators a shared vector from each group to be compared
+               
+               //figure out what groups are being compared in getValues
+               //because we randomizes the order we need to put the results in the correct column in the output file
+               int group1Index, group2Index, pos;
+               group1Index = shared[0]->getGroupIndex();
+               group2Index = shared[1]->getGroupIndex();
+               
+               numGroupComb = 0;
+               int n = 1;
+               for (int i = 0; i < (numGroups - 1); i++) {
+                       for (int l = n; l < numGroups; l++) {
+                               if ((group1Index == i) && (group2Index == l)) {
+                                       pos = numGroupComb;  //pos tells you which column in the output file you are in
+                               }else if ((group1Index == l) && (group2Index == i)) {
+                                       pos = numGroupComb;
+                               }
+                               numGroupComb++;
+                       }
+                       n++;
                }
+               
+               if (estimate->getMultiple() == true) { 
+                       numGroupComb++; 
+                       groupData.resize((numGroupComb*data.size()), 0);
+                       //is this the time its called with all values
+                       if  ((timesCalled % numGroupComb) == 0) { 
+                               //last spot
+                               pos = ((groupData.size()-1) * data.size());
+                       }
+                       //fills groupdata with datas info
+                       for (int i = 0; i < data.size(); i++) {
+                               groupData[pos+i] = data[i];
+                       }
+               }else {
+                       groupData.resize((numGroupComb*data.size()), 0);
+                       //fills groupdata with datas info
+                       for (int i = 0; i < data.size(); i++) {
+                               groupData[pos+i] = data[i];
+                       }
+               }
+               
                //when you get all your groups info then output
                if ((timesCalled % numGroupComb) == 0) {
                        output->output(numSeqs, groupData);     
-                       groupData.clear();
                }
        };
        
        void init(string s)             {       output->initFile(s);    };
        void reset()                    {       output->resetFile();    };
        void close()                    {       output->resetFile();    };
+       bool isCalcMultiple() { return estimate->getMultiple(); }
        
+       string getName()        {  return estimate->getName();  }
+
 private:
+       
        Calculator* estimate;
        FileOutput* output;
-       int nSeqs, timesCalled;
+       int nSeqs, timesCalled, numGroupComb;
        vector<double> data;
        vector<double> groupData;
 };