]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedrabundvector.cpp
fixed bug in summary.shared for groups
[mothur.git] / sharedrabundvector.cpp
index 6bdeed0753e767de6616930a6cdc560c6e0f2610..b35b06d05813f3819cefc2919f5fbb18b4b8c2af 100644 (file)
 using namespace std;
 
 #include "sharedrabundvector.h" 
-#include "datavector.hpp"
 #include "utilities.hpp"
-#include <exception>
-#include "sharedrabundvector.h"
 #include "sabundvector.hpp"
 #include "ordervector.hpp"
 
@@ -65,10 +62,11 @@ SharedRAbundVector::SharedRAbundVector(string id, vector<individual> rav) : Data
 
 SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) {
        try {
-               int i, hold;
+               int i, num;
+               string holdLabel, group
                individual newGuy;
                
-               f >> label >> hold;
+               f >> label >> group >> num;
                
                //initialize data
                for (i=0; i<hold; i++) {
@@ -223,8 +221,10 @@ string SharedRAbundVector::getGroup(){
 void SharedRAbundVector::setGroup(string groupName){
        group = groupName;
 }
-
-
+/***********************************************************************/
+int SharedRAbundVector::getGroupIndex()  { return index; }
+/***********************************************************************/
+void SharedRAbundVector::setGroupIndex(int vIndex)     { index = vIndex; }
 /***********************************************************************/
 int SharedRAbundVector::getNumBins(){
        return numBins;
@@ -247,7 +247,54 @@ int SharedRAbundVector::getMaxRank(){
 SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){
        return *this;                   
 }
+/***********************************************************************/
 
+RAbundVector SharedRAbundVector::getRAbundVector() {
+       try {
+               RAbundVector rav(data.size());
+               
+               for (int i = 0; i < data.size(); i++) {
+                       rav.set(i, data[i].abundance);
+               }
+       
+               return rav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){
+       try {
+               SharedSAbundVector sav(maxRank+1);
+               
+               for(int i=0;i<data.size();i++){
+                       int abund = data[i].abundance;
+                       sav.set(abund, sav.getAbundance(abund) + 1, group);
+               }
+               
+               sav.set(0, 0, group);
+               sav.setLabel(label);
+               sav.setGroup(group);
+               
+               return sav;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SharedRAbundVector class Function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SharedRAbundVector class function getSharedSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
 /***********************************************************************/
 
 SAbundVector SharedRAbundVector::getSAbundVector() {