]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedsobscollectsummary.cpp
adding labels to list file.
[mothur.git] / sharedsobscollectsummary.cpp
index 6815d875fa6d0bf5f1ad88f0fa7e26aeda20568b..204b61c64d779ebe2946d537e5803d9ed36d3d76 100644 (file)
 EstOutput SharedSobsCS::getValues(vector<SharedRAbundVector*> shared){
        try {
                data.resize(1,0);
-               int observed = 0;
+               double observed = 0;
                int numGroups = shared.size();
 
-               for (int i = 0; i < shared[0]->size(); i++) {
+               for (int i = 0; i < shared[0]->getNumBins(); i++) {
                        //get bin values and set sharedByAll 
                        bool sharedByAll = true;
                        for (int j = 0; j < numGroups; j++) {
@@ -34,13 +34,39 @@ EstOutput SharedSobsCS::getValues(vector<SharedRAbundVector*> shared){
                return data;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedSobsCS class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "SharedSobsCS", "getValues");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedSobsCS class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+}
+/***********************************************************************/
+//This returns the number of shared species observed in several groups.  
+//The shared vector is each groups sharedrabundvector.
+
+EstOutput SharedSobsCS::getValues(vector<SharedRAbundVector*> shared, vector<string>& labels){
+       try {
+               data.resize(1,0);
+               double observed = 0;
+               int numGroups = shared.size();
+        labels.clear();
+        
+               for (int i = 0; i < shared[0]->getNumBins(); i++) {
+                       //get bin values and set sharedByAll 
+                       bool sharedByAll = true;
+                       for (int j = 0; j < numGroups; j++) {
+                               if (shared[j]->getAbundance(i) == 0) { sharedByAll = false; }
+                       }
+                       
+                       //they are shared
+                       if (sharedByAll == true) {  observed++;  labels.push_back(m->currentSharedBinLabels[i]); }
+               }
+        
+               data[0] = observed;
+               return data;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SharedSobsCS", "getValues");
                exit(1);
-       }       
+       }
 }
 
-/***********************************************************************/
\ No newline at end of file
+/***********************************************************************/