]> git.donarmstrong.com Git - mothur.git/blobdiff - collect.cpp
fixes while testing
[mothur.git] / collect.cpp
index 76481d1739c2f652b60028c592aabe18d3d54736..79e997de38bc8938bbcdb72d7134a566a7b9a2bb 100644 (file)
@@ -11,7 +11,7 @@
 
 /***********************************************************************/
 
-void Collect::getCurve(int increment = 1){
+int Collect::getCurve(float percentFreq = 0.01){
         try {
                 RAbundVector* lookup = new RAbundVector(order->getNumBins());
                 SAbundVector* rank        = new SAbundVector(order->getMaxRank()+1);
@@ -21,9 +21,17 @@ void Collect::getCurve(int increment = 1){
                 for(int i=0;i<displays.size();i++){
                         ccd->registerDisplay(displays[i]); //adds a display[i] to cdd
                         displays[i]->init(label);                   //sets displays label
-                }                                                                           
+                }   
+                               
+                               //convert freq percentage to number
+                               int increment = 1;
+                               if (percentFreq < 1.0) {  increment = numSeqs * percentFreq;  }
+                               else { increment = percentFreq;  }
+                                                                                                                                                                                                                                                       
                 for(int i=0;i<numSeqs;i++){
-
+                                               
+                                               if (m->control_pressed) { delete lookup; delete rank; delete ccd;  return 1;  }
+                                               
                         int binNumber = order->get(i);
                         int abundance = lookup->get(binNumber);
                 
@@ -50,22 +58,19 @@ void Collect::getCurve(int increment = 1){
                                delete lookup;
                                delete rank;
                                delete ccd;
+                               
+                               return 0;
         }
         catch(exception& e) {
-                cout << "Standard Error: " << e.what() << " has occurred in the Collect class Function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-                exit(1);
-        }
-        catch(...) {
-                cout << "An unknown error has occurred in the Collect class function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-                exit(1);
+                       m->errorOut(e, "Collect", "getCurve");
+                       exit(1);
         }
-
 }
 
 /***********************************************************************/
-void Collect::getSharedCurve(int increment = 1){
+int Collect::getSharedCurve(float percentFreq = 0.01){
 try {
-                globaldata = GlobalData::getInstance();
+                               globaldata = GlobalData::getInstance();
                 vector<SharedRAbundVector*> lookup; 
                                vector<SharedRAbundVector*> subset;
 
@@ -83,22 +88,31 @@ try {
                 //initialize labels for output
                 //makes  'uniqueAB         uniqueAC  uniqueBC' if your groups are A, B, C
                 getGroupComb();
-                groupLabel = ""; 
-                for (int s = 0; s < groupComb.size(); s++) {
-                        groupLabel = groupLabel + label + groupComb[s] + "\t";
-                }
-                               
-                               //for multi displays
-                               string groupLabelAll = groupLabel + label + "all\t";
                                
                 for(int i=0;i<displays.size();i++){
                         ccd->registerDisplay(displays[i]); //adds a display[i] to cdd
-                                               if (displays[i]->isCalcMultiple() == true)  {   displays[i]->init(groupLabelAll); }
+                                               bool hasLciHci = displays[i]->hasLciHci();
+                                               groupLabel = "";
+                                               for (int s = 0; s < groupComb.size(); s++) {
+                                                       if (hasLciHci) {  groupLabel = groupLabel + label + groupComb[s] + "\t" + label + groupComb[s] + "lci\t" + label + groupComb[s] + "hci\t"; }
+                                                       else{  groupLabel = groupLabel + label + groupComb[s] + "\t";  }
+                                               }
+
+                                               string groupLabelAll = groupLabel + label + "all\t"; 
+                                               if ((displays[i]->isCalcMultiple() == true) && (displays[i]->getAll() == true)) {   displays[i]->init(groupLabelAll); }
                                                else {  displays[i]->init(groupLabel);  }           
                 }
                 
+                               //convert freq percentage to number
+                               int increment = 1;
+                               if (percentFreq < 1.0) {  increment = numSeqs * percentFreq;  }
+                               else { increment = percentFreq;  }
+                               
                 //sample all the members
                 for(int i=0;i<numSeqs;i++){
+                               
+                                               if (m->control_pressed) { for (int j = 0; j < lookup.size(); j++) {  delete lookup[j]; } delete ccd;  return 1;  }
+                                               
                         //get first sample
                         individual chosen = sharedorder->get(i);
                         int abundance; 
@@ -111,7 +125,6 @@ try {
                                                                break;
                                                        }
                         }
-                        
        
                         //calculate at 0 and the given increment
                         if((i == 0) || (i+1) % increment == 0){
@@ -134,7 +147,7 @@ try {
                         totalNumSeq = i+1;
                 }
                 
-                //calculate last line if you haven't already
+                //calculate last label if you haven't already
                 if(numSeqs % increment != 0){
                         //how many comparisons to make i.e. for group a, b, c = ab, ac, bc.
                         int n = 1;
@@ -161,17 +174,14 @@ try {
                                for (int i = 0; i < lookup.size(); i++) {
                                        delete lookup[i];
                                }
+                               
+                               return 0;
 
         }
         catch(exception& e) {
-                cout << "Standard Error: " << e.what() << " has occurred in the Collect class Function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-                exit(1);
+                m->errorOut(e, "Collect", "getSharedCurve");
+                               exit(1);
         }
-        catch(...) {
-                cout << "An unknown error has occurred in the Collect class function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-                exit(1);
-        }
-
 }
 
 /**************************************************************************************/
@@ -193,4 +203,4 @@ void Collect::getGroupComb() {
 
 }
 
-/**************************************************************************************/
\ No newline at end of file
+/**************************************************************************************/