]> git.donarmstrong.com Git - mothur.git/blobdiff - rarefact.cpp
numSeqs passing fix
[mothur.git] / rarefact.cpp
index f1b43fc26553cd739d32d2baeff36bc457df006a..691d01708bab5b5bef4118ab38662819280b56de 100644 (file)
 
 /***********************************************************************/
 
-void Rarefact::getCurve(int increment = 1, int nIters = 1000){
+int Rarefact::getCurve(float percentFreq = 0.01, int nIters = 1000){
        try {
                RarefactionCurveData* rcd = new RarefactionCurveData();
                for(int i=0;i<displays.size();i++){
                        rcd->registerDisplay(displays[i]);
                }
-       
+               
+               //convert freq percentage to number
+               int increment = 1;
+               if (percentFreq < 1.0) {  increment = numSeqs * percentFreq;  }
+               else { increment = percentFreq;  }      
+                       
                for(int iter=0;iter<nIters;iter++){
                
                        for(int i=0;i<displays.size();i++){
@@ -31,6 +36,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,16 +68,17 @@ void Rarefact::getCurve(int increment = 1, int nIters = 1000){
                        displays[i]->close();
                }
                delete rcd;
+               return 0;
        }
        catch(exception& e) {
-               errorOut(e, "Rarefact", "getCurve");
+               m->errorOut(e, "Rarefact", "getCurve");
                exit(1);
        }
 }
 
 /***********************************************************************/
 
-void Rarefact::getSharedCurve(int increment = 1, int nIters = 1000){
+int Rarefact::getSharedCurve(float percentFreq = 0.01, int nIters = 1000){
 try {
                SharedRarefactionCurveData* rcd = new SharedRarefactionCurveData();
                
@@ -81,14 +89,24 @@ try {
                        rcd->registerDisplay(displays[i]);
                }
                
+               //if jumble is false all iters will be the same
+               if (globaldata->jumble == false)  {  nIters = 1;  }
+               
+               //convert freq percentage to number
+               int increment = 1;
+               if (percentFreq < 1.0) {  increment = numSeqs * percentFreq;  }
+               else { increment = percentFreq;  }
+               
                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());
@@ -101,6 +119,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]);
@@ -122,9 +142,10 @@ try {
                }
                
                delete rcd;
+               return 0;
        }
        catch(exception& e) {
-               errorOut(e, "Rarefact", "getSharedCurve");
+               m->errorOut(e, "Rarefact", "getSharedCurve");
                exit(1);
        }
 }
@@ -138,7 +159,7 @@ void Rarefact::mergeVectors(SharedRAbundVector* shared1, SharedRAbundVector* sha
                }
        }
        catch(exception& e) {
-               errorOut(e, "Rarefact", "mergeVectors");
+               m->errorOut(e, "Rarefact", "mergeVectors");
                exit(1);
        }
 }