]> git.donarmstrong.com Git - mothur.git/blobdiff - inputdata.cpp
added ordergroup parameter to read.otu
[mothur.git] / inputdata.cpp
index c2f4e4e63347ce62b818617fd4e05da629a84972..65685d6a7e13c09f6563ebb3c2ea3f78dd3fd937 100644 (file)
@@ -15,7 +15,7 @@
 /***********************************************************************/
 
 InputData::InputData(string fName, string f) : format(f){
-       
+       m = MothurOut::getInstance();
        openInputFile(fName, fileHandle);
        filename = fName;
        
@@ -34,7 +34,7 @@ InputData::~InputData(){
 
 InputData::InputData(string fName, string orderFileName, string f) : format(f){
        try {
-               
+               m = MothurOut::getInstance();
                ifstream ofHandle;
                openInputFile(orderFileName, ofHandle);
                string name;
@@ -52,22 +52,18 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){
                openInputFile(fName, fileHandle);
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "InputData");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 /***********************************************************************/
 
 ListVector* InputData::getListVector(){
        try {
-               if(fileHandle){
+               if(!fileHandle.eof()){
                        if(format == "list") {
                                list = new ListVector(fileHandle);
-                       }
+                       }else{ list = NULL;  }
                                        
                        gobble(fileHandle);
                        return list;
@@ -77,17 +73,12 @@ ListVector* InputData::getListVector(){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getListVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
-
 ListVector* InputData::getListVector(string label){
        try {
                ifstream in;
@@ -109,7 +100,7 @@ ListVector* InputData::getListVector(string label){
                                        else {  delete list;    }
                                        gobble(in);
                                }
-                       }
+                       }else{ list = NULL;  }
                        
                        in.close();
                        return list;
@@ -119,15 +110,44 @@ ListVector* InputData::getListVector(string label){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getListVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
+/***********************************************************************/
+ListVector* InputData::getListVector(string label, bool resetFP){
+       try {
+               string  thisLabel;
+               fileHandle.clear();
+               fileHandle.seekg(0);
+               
+               if(fileHandle){
 
+                       if (format == "list") {
+                       
+                               while (fileHandle.eof() != true) {
+                                       
+                                       list = new ListVector(fileHandle); gobble(fileHandle);
+                                       thisLabel = list->getLabel();
+                                       
+                                       //if you are at the last label
+                                       if (thisLabel == label) {  break;  }
+                                       //so you don't loose this memory
+                                       else {  delete list;    }
+                               }
+                       }else{ list = NULL;  }
+               
+                       return list;
+               }
+               else{
+                       return NULL;
+               }
+       }
+       catch(exception& e) {
+               m->errorOut(e, "InputData", "getListVector");
+               exit(1);
+       }
+}
 
 /***********************************************************************/
 
@@ -136,7 +156,7 @@ SharedListVector* InputData::getSharedListVector(){
                if(fileHandle){
                        if (format == "shared")  {
                                SharedList = new SharedListVector(fileHandle);
-                       }
+                       }else{ SharedList = NULL;  }
                                        
                        gobble(fileHandle);
                        return SharedList;
@@ -146,13 +166,9 @@ SharedListVector* InputData::getSharedListVector(){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getSharedListVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 /***********************************************************************/
 
@@ -178,7 +194,7 @@ SharedListVector* InputData::getSharedListVector(string label){
                                        gobble(in);
                                }
 
-                       }
+                       }else{ SharedList = NULL;  }
                                
                        in.close();
                        return SharedList;
@@ -188,13 +204,9 @@ SharedListVector* InputData::getSharedListVector(string label){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getSharedListVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getSharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 
@@ -206,7 +218,7 @@ SharedOrderVector* InputData::getSharedOrderVector(){
                if(fileHandle){
                        if (format == "sharedfile")  {
                                SharedOrder = new SharedOrderVector(fileHandle);
-                       }
+                       }else{ SharedOrder = NULL;  }
                                
                        gobble(fileHandle);
                        return SharedOrder;
@@ -216,13 +228,9 @@ SharedOrderVector* InputData::getSharedOrderVector(){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getSharedOrderVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
@@ -249,7 +257,7 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){
                                        gobble(in);
                                }
 
-                       }
+                       }else{ SharedOrder = NULL;  }
                                
                        in.close();
                        return SharedOrder;
@@ -259,13 +267,9 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getSharedOrderVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 
@@ -290,11 +294,12 @@ OrderVector* InputData::getOrderVector(){
                        else if(format == "sabund"){
                                input = new SAbundVector(fileHandle);
                        }
-                                       
+                       
                        gobble(fileHandle);
-                       output = new OrderVector();
-                       *output = (input->getOrderVector());
                        
+                       output = new OrderVector();     
+                       *output = (input->getOrderVector());
+               
                        return output;
                }
                else{
@@ -302,13 +307,9 @@ OrderVector* InputData::getOrderVector(){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getOrderVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
@@ -409,13 +410,9 @@ OrderVector* InputData::getOrderVector(string label){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getOrderVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
@@ -443,13 +440,9 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
                
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getSharedRAbundVectors");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 /***********************************************************************/
 vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
@@ -505,13 +498,9 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
        
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getSharedRAbundVectors");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 
@@ -548,13 +537,9 @@ SAbundVector* InputData::getSAbundVector(){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getSAbundVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 /***********************************************************************/
 SAbundVector* InputData::getSAbundVector(string label){
@@ -654,13 +639,9 @@ SAbundVector* InputData::getSAbundVector(string label){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getSAbundVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/
@@ -695,13 +676,9 @@ RAbundVector* InputData::getRAbundVector(){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getRAbundVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 /***********************************************************************/
 RAbundVector* InputData::getRAbundVector(string label){
@@ -800,13 +777,9 @@ RAbundVector* InputData::getRAbundVector(string label){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "InputData", "getRAbundVector");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the InputData class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 /***********************************************************************/