]> git.donarmstrong.com Git - mothur.git/blobdiff - rarefact.cpp
added formatmatrix, formatcolumn, and formatphylip classes. Used these classes in...
[mothur.git] / rarefact.cpp
index 5c1ce741c951a620fb68529b834a3fd44e4b1840..5cd9b99c5051be03b00757df6a99bfb479adabfe 100644 (file)
@@ -63,11 +63,7 @@ void Rarefact::getCurve(int increment = 1, int nIters = 1000){
                delete rcd;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the Rarefact class function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "Rarefact", "getCurve");
                exit(1);
        }
 }
@@ -85,24 +81,37 @@ try {
                        rcd->registerDisplay(displays[i]);
                }
                
+               //if jumble is false all iters will be the same
+               if (globaldata->jumble == false)  {  nIters = 1;  }
+               
                for(int iter=0;iter<nIters;iter++){
                
                        for(int i=0;i<displays.size();i++){
                                displays[i]->init(label);                 
                        }
-
-                       //randomize the groups
-                       random_shuffle(lookup.begin(), lookup.end());
+                       
+                       if (globaldata->jumble == true)  {
+                               //randomize the groups
+                               random_shuffle(lookup.begin(), lookup.end());
+                       }
+                       
+                       //make merge the size of lookup[0]
+                       SharedRAbundVector* merge = new SharedRAbundVector(lookup[0]->size());
+                       
+                       //make copy of lookup zero
+                       for(int i = 0; i<lookup[0]->size(); i++) {
+                               merge->set(i, lookup[0]->getAbundance(i), "merge");
+                       }
                        
                        vector<SharedRAbundVector*> subset;
                        //send each group one at a time
                        for (int k = 0; k < lookup.size(); k++) { 
                                subset.clear(); //clears out old pair of sharedrabunds
                                //add in new pair of sharedrabunds
-                               subset.push_back(lookup[0]); subset.push_back(lookup[k]);
+                               subset.push_back(merge); subset.push_back(lookup[k]);
                                
                                rcd->updateSharedData(subset, k+1, numGroupComb);
-                               mergeVectors(lookup[0], lookup[k]);
+                               mergeVectors(merge, lookup[k]);
                        }
 
                        //resets output files
@@ -110,6 +119,7 @@ try {
                                displays[i]->reset();
                        }
                        
+                       delete merge;
                }
                
                for(int i=0;i<displays.size();i++){
@@ -119,14 +129,9 @@ try {
                delete rcd;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the Rarefact class function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "Rarefact", "getSharedCurve");
                exit(1);
        }
-
 }
 
 /**************************************************************************************/
@@ -134,18 +139,12 @@ void Rarefact::mergeVectors(SharedRAbundVector* shared1, SharedRAbundVector* sha
        try{
                for (int k = 0; k < shared1->size(); k++) {
                        //merge new species into shared1
-                       if ((shared1->getAbundance(k) == 0) && (shared2->getAbundance(k) != 0)) {
-                               shared1->set(k, shared2->getAbundance(k), "combo");  //set to 'combo' since this vector now contains multiple groups
-                       }
+                       shared1->set(k, (shared1->getAbundance(k) + shared2->getAbundance(k)), "combo");  //set to 'combo' since this vector now contains multiple groups
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function mergeVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "Rarefact", "mergeVectors");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the Rarefact class function mergeVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }