]> git.donarmstrong.com Git - mothur.git/blobdiff - sabundvector.cpp
added the Calculators Thomas made in the fall. Added parameter and command error...
[mothur.git] / sabundvector.cpp
index a7856193a5777d6e3c1cce515549eea3ff325e01..b29313260df9429f3149a161c4d8e8fbdb976a6a 100644 (file)
@@ -10,6 +10,7 @@ using namespace std;
 
 #include "sabundvector.hpp"
 #include "utilities.hpp"
+#include "calculator.h"
 
 /***********************************************************************/
 
@@ -23,7 +24,6 @@ SAbundVector::SAbundVector(int size) :        DataVector(), data(size, 0), maxRank(0),
 
 SAbundVector::SAbundVector(string id, vector<int> sav) : DataVector(id), data(sav) {
        try {
-               
                for(int i=0;i<sav.size();i++){
                        if(data[i] != 0){       maxRank = i;    }
                        numSeqs += i*data[i];
@@ -42,6 +42,24 @@ SAbundVector::SAbundVector(string id, vector<int> sav) : DataVector(id), data(sa
 
 /***********************************************************************/
 
+SAbundVector::SAbundVector(vector <int> dataVec, int mr, int nb, int ns) {
+       try {
+               data = dataVec;
+               maxRank = mr;
+               numBins = nb;
+               numSeqs = ns;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the SAbundVector class function SAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/***********************************************************************/
+
 SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
        try {
                int hold;
@@ -65,6 +83,7 @@ SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), n
        }
 }
 
+
 /***********************************************************************/
 
 void SAbundVector::set(int sabund, int abundance){
@@ -91,6 +110,7 @@ void SAbundVector::set(int sabund, int abundance){
        }       
 }
 
+
 /***********************************************************************/
 
 int SAbundVector::get(int index){
@@ -118,6 +138,18 @@ void SAbundVector::push_back(int abundance){
                exit(1);
        }               
 }
+/***********************************************************************/
+
+void SAbundVector::quicksort(){
+       sort(data.rbegin(), data.rend());
+}
+
+/***********************************************************************/
+
+int SAbundVector::sum(){
+       VecCalc vecCalc;
+       return vecCalc.sumElements(data);
+}
 
 /***********************************************************************/