]> git.donarmstrong.com Git - mothur.git/blobdiff - rarefact.cpp
added checks for ^C to quit command instead of program
[mothur.git] / rarefact.cpp
index ba0c02e2a474545474e4cf13efbdc633bfbbb3a3..f5e7952688cdbb1dd182ca44df9c152ef46879d9 100644 (file)
@@ -12,7 +12,7 @@
 
 /***********************************************************************/
 
-void Rarefact::getCurve(int increment = 1, int nIters = 1000){
+int Rarefact::getCurve(int increment = 1, int nIters = 1000){
        try {
                RarefactionCurveData* rcd = new RarefactionCurveData();
                for(int i=0;i<displays.size();i++){
@@ -31,6 +31,8 @@ void Rarefact::getCurve(int increment = 1, int nIters = 1000){
                
                        for(int i=0;i<numSeqs;i++){
                        
+                               if (m->control_pressed) { delete lookup; delete rank; delete rcd; return 0;  }
+                       
                                int binNumber = order->get(i);
                                int abundance = lookup->get(binNumber);
                        
@@ -61,20 +63,17 @@ void Rarefact::getCurve(int increment = 1, int nIters = 1000){
                        displays[i]->close();
                }
                delete rcd;
+               return 0;
        }
        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";
+               m->errorOut(e, "Rarefact", "getCurve");
                exit(1);
        }
 }
 
 /***********************************************************************/
 
-void Rarefact::getSharedCurve(int increment = 1, int nIters = 1000){
+int Rarefact::getSharedCurve(int increment = 1, int nIters = 1000){
 try {
                SharedRarefactionCurveData* rcd = new SharedRarefactionCurveData();
                
@@ -85,14 +84,19 @@ 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());
@@ -105,6 +109,8 @@ try {
                        vector<SharedRAbundVector*> subset;
                        //send each group one at a time
                        for (int k = 0; k < lookup.size(); k++) { 
+                               if (m->control_pressed) {  delete merge; delete rcd; return 0;  }
+                               
                                subset.clear(); //clears out old pair of sharedrabunds
                                //add in new pair of sharedrabunds
                                subset.push_back(merge); subset.push_back(lookup[k]);
@@ -118,6 +124,7 @@ try {
                                displays[i]->reset();
                        }
                        
+                       delete merge;
                }
                
                for(int i=0;i<displays.size();i++){
@@ -125,16 +132,12 @@ try {
                }
                
                delete rcd;
+               return 0;
        }
        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";
+               m->errorOut(e, "Rarefact", "getSharedCurve");
                exit(1);
        }
-
 }
 
 /**************************************************************************************/
@@ -146,12 +149,8 @@ void Rarefact::mergeVectors(SharedRAbundVector* shared1, SharedRAbundVector* sha
                }
        }
        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";
+               m->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);
-       }       
 }