]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedutilities.cpp
added bootstrap.shared command and fixed some bugs with heatmap
[mothur.git] / sharedutilities.cpp
index 4e35ff3df44fcf24df6accc2c0b920ecac60bcd9..edd16c7cdee387c1c83f50471d6caf025c8352ec 100644 (file)
@@ -30,7 +30,7 @@ void SharedUtil::getSharedVectors(vector<string> Groups, vector<SharedRAbundVect
                        temp->setGroup(Groups[i]);
                        lookup.push_back(temp);
                }
-               
+       
                int numSeqs = order->size();
                //sample all the members
                for(int i=0;i<numSeqs;i++){
@@ -57,6 +57,55 @@ void SharedUtil::getSharedVectors(vector<string> Groups, vector<SharedRAbundVect
                exit(1);
        }
 }
+/**************************************************************************************************/
+
+void SharedUtil::getSharedVectorswithReplacement(vector<string> Groups, vector<SharedRAbundVector*>& lookup, SharedOrderVector* order) {
+       try {
+       
+               //delete each sharedrabundvector in lookup
+               for (int j = 0; j < lookup.size(); j++) {
+                       delete lookup[j];
+               }
+               
+               lookup.clear();
+               
+               //create and initialize vector of sharedvectors, one for each group
+               for (int i = 0; i < Groups.size(); i++) { 
+                       SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
+                       temp->setLabel(order->getLabel());
+                       temp->setGroup(Groups[i]);
+                       lookup.push_back(temp);
+               }
+       
+               int numSeqs = order->size();
+               
+               //sample all the members
+               for(int i=0;i<numSeqs;i++){
+                       //get random number
+                       int random = int((float)(i+1) * (float)(rand()) / ((float)RAND_MAX+1.0));
+                       individual chosen = order->get(random);
+
+                       int abundance; 
+                       //set info for sharedvector in chosens group
+                       for (int j = 0; j < lookup.size(); j++) { 
+                               if (chosen.group == lookup[j]->getGroup()) {
+                                        abundance = lookup[j]->getAbundance(chosen.bin);
+                                        lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
+                                        break;
+                               }
+                       }
+               }
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function getSharedVectorswithReplacement. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedUtil class function getSharedVectorswithReplacement. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
 
 /**************************************************************************************************/
 //need to have mode because different commands require different number of valid groups