]> git.donarmstrong.com Git - mothur.git/blobdiff - listvector.cpp
added zap method to classify.seqs and changed bayesian method name to wang.
[mothur.git] / listvector.cpp
index 3af7cfe93f2d2b6dba45ab7b9ae5cd8c17184255..9369a12280b35cd41a6a6e3548258f27ebb36b5c 100644 (file)
@@ -7,25 +7,20 @@
  *
  */
 
-using namespace std;
 
-#include <map>
-#include <exception>
 #include "sabundvector.hpp"
 #include "rabundvector.hpp"
 #include "ordervector.hpp"
-#include "datavector.hpp"
-#include "utilities.hpp"
 #include "listvector.hpp"
 
 
 /***********************************************************************/
 
-ListVector::ListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){};
+ListVector::ListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){}
 
 /***********************************************************************/
 
-ListVector::ListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){};
+ListVector::ListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){}
 
 /***********************************************************************/
 
@@ -33,7 +28,7 @@ ListVector::ListVector(string id, vector<string> lv) : DataVector(id), data(lv){
        try {
                for(int i=0;i<data.size();i++){
                        if(data[i] != ""){
-                               int binSize = getNumNames(data[i]);
+                               int binSize = m->getNumNames(data[i]);
                                numBins = i+1;
                                if(binSize > maxRank)   {       maxRank = binSize;      }
                                numSeqs += binSize;
@@ -41,11 +36,7 @@ ListVector::ListVector(string id, vector<string> lv) : DataVector(id), data(lv){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "ListVector", "ListVector");
                exit(1);
        }
 }
@@ -64,13 +55,10 @@ ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numS
                        f >> inputData;
                        set(i, inputData);
                }
+               m->gobble(f);
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ListVector class function ListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "ListVector", "ListVector");
                exit(1);
        }
 }
@@ -79,9 +67,9 @@ ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numS
 
 void ListVector::set(int binNumber, string seqNames){
        try {
-               int nNames_old = getNumNames(data[binNumber]);
+               int nNames_old = m->getNumNames(data[binNumber]);
                data[binNumber] = seqNames;
-               int nNames_new = getNumNames(seqNames);
+               int nNames_new = m->getNumNames(seqNames);
        
                if(nNames_old == 0)                     {       numBins++;                              }
                if(nNames_new == 0)                     {       numBins--;                              }
@@ -90,11 +78,7 @@ void ListVector::set(int binNumber, string seqNames){
                numSeqs += (nNames_new - nNames_old);
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ListVector class function set. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "ListVector", "set");
                exit(1);
        }
 }
@@ -110,7 +94,7 @@ string ListVector::get(int index){
 void ListVector::push_back(string seqNames){
        try {
                data.push_back(seqNames);
-               int nNames = getNumNames(seqNames);
+               int nNames = m->getNumNames(seqNames);
        
                numBins++;
        
@@ -119,11 +103,7 @@ void ListVector::push_back(string seqNames){
                numSeqs += nNames;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ListVector 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 ListVector class function push_back. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "ListVector", "push_back");
                exit(1);
        }
 }
@@ -163,11 +143,7 @@ void ListVector::print(ostream& output){
                output << endl;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ListVector class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "ListVector", "print");
                exit(1);
        }
 }
@@ -180,7 +156,7 @@ RAbundVector ListVector::getRAbundVector(){
                RAbundVector rav;
        
                for(int i=0;i<data.size();i++){
-                       int binSize = getNumNames(data[i]);
+                       int binSize = m->getNumNames(data[i]);
                        rav.push_back(binSize);
                }
        
@@ -198,11 +174,7 @@ RAbundVector ListVector::getRAbundVector(){
                return rav;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ListVector class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "ListVector", "getRAbundVector");
                exit(1);
        }
 }
@@ -214,7 +186,7 @@ SAbundVector ListVector::getSAbundVector(){
                SAbundVector sav(maxRank+1);
        
                for(int i=0;i<data.size();i++){
-                       int binSize = getNumNames(data[i]);     
+                       int binSize = m->getNumNames(data[i]);  
                        sav.set(binSize, sav.get(binSize) + 1); 
                }
                sav.set(0, 0);
@@ -223,41 +195,11 @@ SAbundVector ListVector::getSAbundVector(){
                return sav;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ListVector class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "ListVector", "getSAbundVector");
                exit(1);
        }
 }
 
-/***********************************************************************/
-SharedOrderVector* ListVector::getSharedOrderVector(){
-       globaldata = GlobalData::getInstance();
-       string groupName, names, name;
-       groupmap = globaldata->gGroupmap;
-       SharedOrderVector* order;
-       order = new SharedOrderVector();
-       order->setLabel(label);
-       
-       for(int i=0;i<numBins;i++){
-               int binSize = getNumNames(get(i));      //find number of individual in given bin        
-               names = get(i);
-               while (names.find_first_of(',') != -1) { 
-                       name = names.substr(0,names.find_first_of(','));
-                       names = names.substr(names.find_first_of(',')+1, names.length());
-                       groupName = groupmap->getGroup(name);
-                       order->push_back(i, binSize, groupName);  //i represents what bin you are in
-               }
-               //get last name
-               groupName = groupmap->getGroup(names);
-               order->push_back(i, binSize, groupName);
-       }
-       random_shuffle(order->begin(), order->end());
-       return order;
-}
-
 /***********************************************************************/
 
 OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
@@ -267,7 +209,7 @@ OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
                        OrderVector ov;
                
                        for(int i=0;i<data.size();i++){
-                               int binSize = getNumNames(data[i]);             
+                               int binSize = m->getNumNames(data[i]);          
                                for(int j=0;j<binSize;j++){
                                        ov.push_back(i);
                                }
@@ -295,7 +237,7 @@ OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
                                        }
                                        else{
                                                if(orderMap->count(seqName) == 0){
-                                                       cerr << seqName << " not found, check *.names file\n";
+                                                       m->mothurOut(seqName + " not found, check *.names file\n");
                                                        exit(1);
                                                }
                                        
@@ -305,7 +247,7 @@ OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
                                }
                        
                                if(orderMap->count(seqName) == 0){
-                                       cerr << seqName << " not found, check *.names file\n";
+                                       m->mothurOut(seqName + " not found, check *.names file\n");
                                        exit(1);
                                }
                                ov.set((*orderMap)[seqName], i);        
@@ -318,11 +260,7 @@ OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ListVector class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ListVector class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "ListVector", "getOrderVector");
                exit(1);
        }
 }