]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedordervector.cpp
fixed some bugs
[mothur.git] / sharedordervector.cpp
index 41daa8024713190e997fcb845c144731252386ed..d0c97f9ab5a16655a381ffb3390dbb4cf94d420a 100644 (file)
@@ -7,11 +7,8 @@
  *
  */
 
-using namespace std;
-
-
 #include "sharedordervector.h"
-
+#include "sharedutilities.h"
 
 /***********************************************************************/
 
@@ -149,7 +146,7 @@ individual SharedOrderVector::get(int index){
 
 
 /***********************************************************************/
-
+//commented updateStats out to improve speed, but whoever calls this must remember to update when they are done with all the pushbacks they are doing 
 void SharedOrderVector::push_back(int binNumber, int abund, string groupName){
        individual newGuy;
        newGuy.group = groupName;
@@ -159,7 +156,8 @@ void SharedOrderVector::push_back(int binNumber, int abund, string groupName){
        //numSeqs++;
        //numBins++;
        //if (abund > maxRank) { maxRank = abund; }
-       updateStats();
+       
+       //updateStats();
 }
 
 /***********************************************************************/
@@ -296,6 +294,28 @@ SharedRAbundVector SharedOrderVector::getSharedRAbundVector(string group) {
                exit(1);
        }
        
+}
+/***********************************************************************/
+vector<SharedRAbundVector*> SharedOrderVector::getSharedRAbundVector() {
+       try {
+               SharedUtil* util;
+               util = new SharedUtil();
+               vector<SharedRAbundVector*> lookup;
+               
+               util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups);
+               util->getSharedVectors(globaldata->Groups, lookup, this);
+               
+               return lookup;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedOrderVector class function getSharedRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       
 }
 /***********************************************************************/
 SharedSAbundVector SharedOrderVector::getSharedSAbundVector(string group) {
@@ -319,6 +339,7 @@ SharedSAbundVector SharedOrderVector::getSharedSAbundVector(string group) {
 /***********************************************************************/
 
 SharedOrderVector SharedOrderVector::getSharedOrderVector(){
+       random_shuffle(data.begin(), data.end());
        return *this;                   
 }
 
@@ -331,25 +352,18 @@ void SharedOrderVector::updateStats(){
                numBins = 0;
                maxRank = 0;
        
-               for(int i=0;i<data.size();i++){
-                       if(data[i].bin != -1){
-                               numSeqs++;
-                       }
-               }
-       
-               vector<individual> hold(numSeqs);
-       
+               numSeqs = data.size();
+                               
+               vector<int> hold(numSeqs, 0);
                for(int i=0;i<numSeqs;i++){
-                       if(data[i].bin != -1){
-                               hold[data[i].bin].bin = hold[data[i].bin].bin+1;
-                       }
+                       hold[data[i].bin] = hold[data[i].bin]+1;
                }       
-
+               
                for(int i=0;i<numSeqs;i++){
-                       if(data[i].bin > numBins) { numBins = data[i].bin;      } 
-                       if(data[i].abundance > maxRank) {       maxRank = data[i].abundance;    }
+                       if(hold[i] > 0)                         {       numBins++;                              }
+                       if(hold[i] > maxRank)           {       maxRank = hold[i];              }
                }
-               numBins++; //if you have 10 bins largest .bin is 9 since we start at 0.
+               
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the SharedOrderVector class Function updateStats. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";