]> git.donarmstrong.com Git - mothur.git/blobdiff - sabundvector.cpp
added sorted parameter to get.oturep, added error checking to chimera classes in...
[mothur.git] / sabundvector.cpp
index a7856193a5777d6e3c1cce515549eea3ff325e01..b70c642643cfd746e63c236e328feb8e37d74a44 100644 (file)
@@ -6,24 +6,22 @@
  *  Copyright 2008 Patrick D. Schloss. All rights resesaved.
  *
  */
-using namespace std;
 
 #include "sabundvector.hpp"
-#include "utilities.hpp"
+#include "calculator.h"
 
 /***********************************************************************/
 
-SAbundVector::SAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
+SAbundVector::SAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){}
 
 /***********************************************************************/
 
-SAbundVector::SAbundVector(int size) : DataVector(), data(size, 0), maxRank(0), numBins(0), numSeqs(0) {};
+SAbundVector::SAbundVector(int size) : DataVector(), data(size, 0), maxRank(0), numBins(0), numSeqs(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];
@@ -31,15 +29,25 @@ SAbundVector::SAbundVector(string id, vector<int> sav) : DataVector(id), data(sa
                }
        }
        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";
+               errorOut(e, "SAbundVector", "SAbundVector");
                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";
+}
+
+/***********************************************************************/
+
+SAbundVector::SAbundVector(vector <int> dataVec, int mr, int nb, int ns) {
+       try {
+               data = dataVec;
+               maxRank = mr;
+               numBins = nb;
+               numSeqs = ns;
+       }
+       catch(exception& e) {
+               errorOut(e, "SAbundVector", "SAbundVector");
                exit(1);
        }
 }
-
 /***********************************************************************/
 
 SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), numSeqs(0) {
@@ -56,15 +64,12 @@ SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), n
                }
        }
        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";
+               errorOut(e, "SAbundVector", "SAbundVector");
                exit(1);
        }
 }
 
+
 /***********************************************************************/
 
 void SAbundVector::set(int sabund, int abundance){
@@ -82,15 +87,12 @@ void SAbundVector::set(int sabund, int abundance){
                if(sabund > maxRank)    {       maxRank = sabund;               }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "SAbundVector", "set");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the SAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
+
 /***********************************************************************/
 
 int SAbundVector::get(int index){
@@ -110,13 +112,21 @@ void SAbundVector::push_back(int abundance){
                numSeqs += (maxRank * abundance);
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "SAbundVector", "push_back");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the SAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
+}
+/***********************************************************************/
+
+void SAbundVector::quicksort(){
+       sort(data.rbegin(), data.rend());
+}
+
+/***********************************************************************/
+
+int SAbundVector::sum(){
+       VecCalc vecCalc;
+       return vecCalc.sumElements(data);
 }
 
 /***********************************************************************/
@@ -153,13 +163,9 @@ void SAbundVector::print(ostream& output){
                output << endl;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "SAbundVector", "print");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the SAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
 }
 
 /**********************************************************************/
@@ -197,13 +203,9 @@ RAbundVector SAbundVector::getRAbundVector(){
                return rav;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "SAbundVector", "getRAbundVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the SAbundVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
 }
 
 /***********************************************************************/
@@ -236,13 +238,9 @@ OrderVector SAbundVector::getOrderVector(map<string,int>* hold = NULL){
                return ov;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "SAbundVector", "getOrderVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the SAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
 }
 
 /***********************************************************************/