]> git.donarmstrong.com Git - mothur.git/blobdiff - rabundvector.cpp
working on pam
[mothur.git] / rabundvector.cpp
index d6b7d1225691e9287c94679317fa2ece34caf158..6cbaa0d896ad7d47105873c67cdc6d003329b83a 100644 (file)
@@ -6,26 +6,24 @@
  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
  *
  */
-using namespace std;
  
-
-#include "utilities.hpp"
 #include "rabundvector.hpp"
 #include "sabundvector.hpp"
 #include "ordervector.hpp"
+#include "calculator.h"
 
 
 /***********************************************************************/
 
-RAbundVector::RAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {};
+RAbundVector::RAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {}
 
 /***********************************************************************/
 
-RAbundVector::RAbundVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(0), numSeqs(0) {};
+RAbundVector::RAbundVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(0), numSeqs(0) {}
 
 /***********************************************************************/
 
-//RAbundVector::RAbundVector(const RAbundVector& rav) : DataVector(rav), data(rav.data), (rav.label),  (rav.maxRank), (rav.numBins), (rav.numSeqs){};
+//RAbundVector::RAbundVector(const RAbundVector& rav) : DataVector(rav), data(rav.data), (rav.label),  (rav.maxRank), (rav.numBins), (rav.numSeqs){}
 
 
 /***********************************************************************/
@@ -43,16 +41,26 @@ RAbundVector::RAbundVector(string id, vector<int> rav) : DataVector(id), data(ra
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "RAbundVector", "RAbundVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+}
+
+/***********************************************************************/
+
+RAbundVector::RAbundVector(vector<int> rav, int mr, int nb, int ns) {
+       try {
+               numBins = nb;
+               maxRank = mr;
+               numSeqs = ns;
+               data = rav;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RAbundVector", "RAbundVector");
                exit(1);
        }
 }
 
-
 /***********************************************************************/
 
 
@@ -70,11 +78,7 @@ RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0),
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the RAbundVector class function RAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "RAbundVector", "RAbundVector");
                exit(1);
        }
 }
@@ -99,11 +103,7 @@ void RAbundVector::set(int binNumber, int newBinSize){
                numSeqs += (newBinSize - oldBinSize);
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the RAbundVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "RAbundVector", "set");
                exit(1);
        }
 }
@@ -114,7 +114,15 @@ int RAbundVector::get(int index){
        return data[index];
        
 }
+/***********************************************************************/
 
+void RAbundVector::clear(){
+       numBins = 0;
+       maxRank = 0;
+       numSeqs = 0;
+       data.clear();
+       
+}
 /***********************************************************************/
 
 void RAbundVector::push_back(int binSize){
@@ -129,11 +137,7 @@ void RAbundVector::push_back(int binSize){
                numSeqs += binSize;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the RAbundVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "RAbundVector", "push_back");
                exit(1);
        }
 }
@@ -160,6 +164,33 @@ int RAbundVector::size(){
 
 /***********************************************************************/
 
+void RAbundVector::quicksort(){
+       sort(data.rbegin(), data.rend());
+}
+
+/***********************************************************************/
+
+int RAbundVector::sum(){
+       VecCalc vecCalc;
+       return vecCalc.sumElements(data);
+}
+
+/***********************************************************************/
+
+int RAbundVector::sum(int index){
+       VecCalc vecCalc;
+       return vecCalc.sumElements(data, index);
+}
+
+/***********************************************************************/
+
+int RAbundVector::numNZ(){
+       VecCalc vecCalc;
+       return vecCalc.numNZ(data);
+}
+
+/***********************************************************************/
+
 vector<int>::reverse_iterator RAbundVector::rbegin(){
        return data.rbegin();                           
 }
@@ -170,6 +201,19 @@ vector<int>::reverse_iterator RAbundVector::rend(){
        return data.rend();                                     
 }
 
+/***********************************************************************/
+void RAbundVector::nonSortedPrint(ostream& output){
+       try {   
+               output << label << '\t' << numBins << '\t';
+       
+               for(int i=0;i<numBins;i++){             output << data[i] << '\t';              }
+               output << endl;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RAbundVector", "nonSortedPrint");
+               exit(1);
+       }
+}
 /***********************************************************************/
 void RAbundVector::print(string prefix, ostream& output){
        try {   
@@ -182,15 +226,12 @@ void RAbundVector::print(string prefix, ostream& output){
                output << endl;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "RAbundVector", "print");
                exit(1);
        }
 }
 
+
 /***********************************************************************/
 void RAbundVector::print(ostream& output){
        try {
@@ -203,11 +244,7 @@ void RAbundVector::print(ostream& output){
                output << endl;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the RAbundVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "RAbundVector", "print");
                exit(1);
        }
 }
@@ -250,11 +287,7 @@ SAbundVector RAbundVector::getSAbundVector() {
                return sav;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the RAbundVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "RAbundVector", "getSAbundVector");
                exit(1);
        }
 }
@@ -264,23 +297,20 @@ SAbundVector RAbundVector::getSAbundVector() {
 OrderVector RAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
        try {
                OrderVector ov;
-       
+
                for(int i=0;i<data.size();i++){
                        for(int j=0;j<data[i];j++){
                                ov.push_back(i);
                        }
                }
                random_shuffle(ov.begin(), ov.end());
-
                ov.setLabel(label);     
+               ov.getNumBins();
+
                return ov;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the RAbundVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the RAbundVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "RAbundVector", "getOrderVector");
                exit(1);
        }
 }