]> git.donarmstrong.com Git - mothur.git/blobdiff - inputdata.cpp
initial add of metastats
[mothur.git] / inputdata.cpp
index cbf44ed11a96a03c251fcc3025b185c2020c2830..dc99a6898ddc57cde2e1442642b766775dc264b2 100644 (file)
@@ -15,8 +15,9 @@
 /***********************************************************************/
 
 InputData::InputData(string fName, string f) : format(f){
-       
-       openInputFile(fName, fileHandle);
+       m = MothurOut::getInstance();
+       globaldata = GlobalData::getInstance();
+       m->openInputFile(fName, fileHandle);
        filename = fName;
        
 }
@@ -26,6 +27,8 @@ InputData::InputData(string fName, string f) : format(f){
 
 InputData::~InputData(){
        fileHandle.close();
+       globaldata = GlobalData::getInstance();
+       globaldata->saveNextLabel = "";
 //     delete output;
        
 }
@@ -34,9 +37,10 @@ InputData::~InputData(){
 
 InputData::InputData(string fName, string orderFileName, string f) : format(f){
        try {
-               
+               m = MothurOut::getInstance();
+               globaldata = GlobalData::getInstance();
                ifstream ofHandle;
-               openInputFile(orderFileName, ofHandle);
+               m->openInputFile(orderFileName, ofHandle);
                string name;
 
                int count = 0;
@@ -45,14 +49,14 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){
                        ofHandle >> name;
                        orderMap[name] = count;
                        count++;
-                       gobble(ofHandle);
+                       m->gobble(ofHandle);
                }
                ofHandle.close();
        
-               openInputFile(fName, fileHandle);
+               m->openInputFile(fName, fileHandle);
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "InputData");
+               m->errorOut(e, "InputData", "InputData");
                exit(1);
        }
 }
@@ -60,12 +64,12 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){
 
 ListVector* InputData::getListVector(){
        try {
-               if(fileHandle){
+               if(!fileHandle.eof()){
                        if(format == "list") {
                                list = new ListVector(fileHandle);
-                       }
+                       }else{ list = NULL;  }
                                        
-                       gobble(fileHandle);
+                       m->gobble(fileHandle);
                        return list;
                }
                else{
@@ -73,18 +77,17 @@ ListVector* InputData::getListVector(){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getListVector");
+               m->errorOut(e, "InputData", "getListVector");
                exit(1);
        }
 }
 
 /***********************************************************************/
-
 ListVector* InputData::getListVector(string label){
        try {
                ifstream in;
                string  thisLabel;
-               openInputFile(filename, in);
+               m->openInputFile(filename, in);
                
                if(in){
 
@@ -99,9 +102,9 @@ ListVector* InputData::getListVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete list;    }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
-                       }
+                       }else{ list = NULL;  }
                        
                        in.close();
                        return list;
@@ -111,11 +114,44 @@ ListVector* InputData::getListVector(string label){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getListVector");
+               m->errorOut(e, "InputData", "getListVector");
                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); m->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);
+       }
+}
 
 /***********************************************************************/
 
@@ -124,9 +160,9 @@ SharedListVector* InputData::getSharedListVector(){
                if(fileHandle){
                        if (format == "shared")  {
                                SharedList = new SharedListVector(fileHandle);
-                       }
+                       }else{ SharedList = NULL;  }
                                        
-                       gobble(fileHandle);
+                       m->gobble(fileHandle);
                        return SharedList;
                }
                else{
@@ -134,7 +170,7 @@ SharedListVector* InputData::getSharedListVector(){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getSharedListVector");
+               m->errorOut(e, "InputData", "getSharedListVector");
                exit(1);
        }
 }
@@ -144,7 +180,7 @@ SharedListVector* InputData::getSharedListVector(string label){
        try {
                ifstream in;
                string  thisLabel;
-               openInputFile(filename, in);
+               m->openInputFile(filename, in);
                
                if(in){
 
@@ -159,10 +195,10 @@ SharedListVector* InputData::getSharedListVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete SharedList;      }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
 
-                       }
+                       }else{ SharedList = NULL;  }
                                
                        in.close();
                        return SharedList;
@@ -172,7 +208,7 @@ SharedListVector* InputData::getSharedListVector(string label){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getSharedListVector");
+               m->errorOut(e, "InputData", "getSharedListVector");
                exit(1);
        }
 }
@@ -186,9 +222,9 @@ SharedOrderVector* InputData::getSharedOrderVector(){
                if(fileHandle){
                        if (format == "sharedfile")  {
                                SharedOrder = new SharedOrderVector(fileHandle);
-                       }
+                       }else{ SharedOrder = NULL;  }
                                
-                       gobble(fileHandle);
+                       m->gobble(fileHandle);
                        return SharedOrder;
                        
                }else{
@@ -196,7 +232,7 @@ SharedOrderVector* InputData::getSharedOrderVector(){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getSharedOrderVector");
+               m->errorOut(e, "InputData", "getSharedOrderVector");
                exit(1);
        }
 }
@@ -207,7 +243,7 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){
        try {
                ifstream in;
                string  thisLabel;
-               openInputFile(filename, in);
+               m->openInputFile(filename, in);
                
                if(in){
 
@@ -222,10 +258,10 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete SharedOrder;     }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
 
-                       }
+                       }else{ SharedOrder = NULL;  }
                                
                        in.close();
                        return SharedOrder;
@@ -235,7 +271,7 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getSharedOrderVector");
+               m->errorOut(e, "InputData", "getSharedOrderVector");
                exit(1);
        }
 }
@@ -262,11 +298,12 @@ OrderVector* InputData::getOrderVector(){
                        else if(format == "sabund"){
                                input = new SAbundVector(fileHandle);
                        }
-                                       
-                       gobble(fileHandle);
-                       output = new OrderVector();
-                       *output = (input->getOrderVector());
                        
+                       m->gobble(fileHandle);
+                       
+                       output = new OrderVector();     
+                       *output = (input->getOrderVector());
+               
                        return output;
                }
                else{
@@ -274,7 +311,7 @@ OrderVector* InputData::getOrderVector(){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getOrderVector");
+               m->errorOut(e, "InputData", "getOrderVector");
                exit(1);
        }
 }
@@ -285,7 +322,7 @@ OrderVector* InputData::getOrderVector(string label){
        
                ifstream in;
                string  thisLabel;
-               openInputFile(filename, in);
+               m->openInputFile(filename, in);
                
                if(in){
                        if((format == "list") || (format == "listorder")) {
@@ -299,7 +336,7 @@ OrderVector* InputData::getOrderVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
                        }
                        else if (format == "shared")  {
@@ -313,7 +350,7 @@ OrderVector* InputData::getOrderVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
 
                        }
@@ -328,7 +365,7 @@ OrderVector* InputData::getOrderVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
 
                        }
@@ -343,7 +380,7 @@ OrderVector* InputData::getOrderVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
 
                        }
@@ -358,7 +395,7 @@ OrderVector* InputData::getOrderVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                        
                                }
 
@@ -377,7 +414,7 @@ OrderVector* InputData::getOrderVector(string label){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getOrderVector");
+               m->errorOut(e, "InputData", "getOrderVector");
                exit(1);
        }
 }
@@ -398,7 +435,7 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
                                        return SharedList->getSharedRAbundVector();
                                }
                        }
-                       gobble(fileHandle);
+                       m->gobble(fileHandle);
                }
                                
                //this is created to signal to calling function that the input file is at eof
@@ -407,7 +444,7 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
                
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getSharedRAbundVectors");
+               m->errorOut(e, "InputData", "getSharedRAbundVectors");
                exit(1);
        }
 }
@@ -417,8 +454,9 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
                ifstream in;
                string  thisLabel;
                
-               openInputFile(filename, in);
-               
+               m->openInputFile(filename, in);
+               globaldata->saveNextLabel = "";
+       
                if(in){
                        if (format == "sharedfile")  {
                                while (in.eof() != true) {
@@ -426,6 +464,7 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
                                        SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
                                        if (SharedRAbund != NULL) {
                                                thisLabel = SharedRAbund->getLabel();
+                                       
                                                //if you are at the last label
                                                if (thisLabel == label) {  in.close(); return SharedRAbund->getSharedRAbundVectors();  }
                                                else {
@@ -435,7 +474,7 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
                                                        delete SharedRAbund;
                                                }
                                        }else{  break;  }
-                                       gobble(in);
+                                       m->gobble(in);
                                        
                                }
                        }else if (format == "shared") {
@@ -451,7 +490,7 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
                                                        delete SharedList;
                                                }
                                        }else{  break;  }
-                                       gobble(in);
+                                       m->gobble(in);
                                        
                                }
                        
@@ -465,12 +504,76 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
        
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getSharedRAbundVectors");
+               m->errorOut(e, "InputData", "getSharedRAbundVectors");
                exit(1);
        }
 }
 
-
+/***********************************************************************/
+//this is used when you don't need the order vector
+vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(){
+       try {
+               if(fileHandle){
+                       if (format == "relabund")  {
+                               SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(fileHandle);
+                               if (SharedRelAbund != NULL) {
+                                       return SharedRelAbund->getSharedRAbundFloatVectors();
+                               }
+                       }
+                       m->gobble(fileHandle);
+               }
+                               
+               //this is created to signal to calling function that the input file is at eof
+               vector<SharedRAbundFloatVector*> null;  null.push_back(NULL);
+               return null;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
+               exit(1);
+       }
+}
+/***********************************************************************/
+vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string label){
+       try {
+               ifstream in;
+               string  thisLabel;
+               
+               m->openInputFile(filename, in);
+               globaldata->saveNextLabel = "";
+               
+               if(in){
+                       if (format == "sharedfile")  {
+                               while (in.eof() != true) {
+                                       
+                                       SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in);
+                                       if (SharedRelAbund != NULL) {
+                                               thisLabel = SharedRelAbund->getLabel();
+                                               //if you are at the last label
+                                               if (thisLabel == label) {  in.close(); return SharedRelAbund->getSharedRAbundFloatVectors();  }
+                                               else {
+                                                       //so you don't loose this memory
+                                                       vector<SharedRAbundFloatVector*> lookup = SharedRelAbund->getSharedRAbundFloatVectors(); 
+                                                       for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
+                                                       delete SharedRelAbund;
+                                               }
+                                       }else{  break;  }
+                                       m->gobble(in);
+                               }
+                       }
+               }
+                               
+               //this is created to signal to calling function that the input file is at eof
+               vector<SharedRAbundFloatVector*> null;  null.push_back(NULL);
+               in.close();
+               return null;
+       
+       }
+       catch(exception& e) {
+               m->errorOut(e, "InputData", "getSharedRAbundFloatVectors");
+               exit(1);
+       }
+}
 /***********************************************************************/
 
 SAbundVector* InputData::getSAbundVector(){
@@ -492,7 +595,7 @@ SAbundVector* InputData::getSAbundVector(){
                                input = new SAbundVector(fileHandle);
                        }
                                        
-                       gobble(fileHandle);
+                       m->gobble(fileHandle);
 
                        sabund = new SAbundVector();
                        *sabund = (input->getSAbundVector());
@@ -504,7 +607,7 @@ SAbundVector* InputData::getSAbundVector(){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getSAbundVector");
+               m->errorOut(e, "InputData", "getSAbundVector");
                exit(1);
        }
 }
@@ -514,7 +617,7 @@ SAbundVector* InputData::getSAbundVector(string label){
        
                ifstream in;
                string  thisLabel;
-               openInputFile(filename, in);
+               m->openInputFile(filename, in);
                
                if(in){
                        if (format == "list") {
@@ -528,7 +631,7 @@ SAbundVector* InputData::getSAbundVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
                        }
                        else if (format == "shared")  {
@@ -542,7 +645,7 @@ SAbundVector* InputData::getSAbundVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
 
                        }
@@ -557,7 +660,7 @@ SAbundVector* InputData::getSAbundVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
 
                        }
@@ -572,7 +675,7 @@ SAbundVector* InputData::getSAbundVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
 
                        }
@@ -587,7 +690,7 @@ SAbundVector* InputData::getSAbundVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                        
                                }
 
@@ -606,7 +709,7 @@ SAbundVector* InputData::getSAbundVector(string label){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getSAbundVector");
+               m->errorOut(e, "InputData", "getSAbundVector");
                exit(1);
        }
 }
@@ -631,7 +734,7 @@ RAbundVector* InputData::getRAbundVector(){
                                input = new SAbundVector(fileHandle);
                        }
                                        
-                       gobble(fileHandle);
+                       m->gobble(fileHandle);
 
                        rabund = new RAbundVector();
                        *rabund = (input->getRAbundVector());
@@ -643,7 +746,7 @@ RAbundVector* InputData::getRAbundVector(){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getRAbundVector");
+               m->errorOut(e, "InputData", "getRAbundVector");
                exit(1);
        }
 }
@@ -653,7 +756,7 @@ RAbundVector* InputData::getRAbundVector(string label){
        
                ifstream in;
                string  thisLabel;
-               openInputFile(filename, in);
+               m->openInputFile(filename, in);
                
                if(in){
                        if (format == "list") {
@@ -667,7 +770,7 @@ RAbundVector* InputData::getRAbundVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
                        }
                        else if (format == "shared")  {
@@ -681,7 +784,7 @@ RAbundVector* InputData::getRAbundVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
 
                        }
@@ -696,7 +799,7 @@ RAbundVector* InputData::getRAbundVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
 
                        }
@@ -711,7 +814,7 @@ RAbundVector* InputData::getRAbundVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                }
 
                        }
@@ -726,7 +829,7 @@ RAbundVector* InputData::getRAbundVector(string label){
                                        if (thisLabel == label) {  break;  }
                                        //so you don't loose this memory
                                        else {  delete input;   }
-                                       gobble(in);
+                                       m->gobble(in);
                                        
                                }
 
@@ -744,7 +847,7 @@ RAbundVector* InputData::getRAbundVector(string label){
                }
        }
        catch(exception& e) {
-               errorOut(e, "InputData", "getRAbundVector");
+               m->errorOut(e, "InputData", "getRAbundVector");
                exit(1);
        }
 }