]> git.donarmstrong.com Git - mothur.git/blobdiff - inputdata.cpp
sffinfo bug with flow grams right index when clipQualRight=0
[mothur.git] / inputdata.cpp
index dc99a6898ddc57cde2e1442642b766775dc264b2..8b1829a3db697df21b3d0f64bf6be6cfea15c536 100644 (file)
 
 InputData::InputData(string fName, string f) : format(f){
        m = MothurOut::getInstance();
-       globaldata = GlobalData::getInstance();
        m->openInputFile(fName, fileHandle);
        filename = fName;
-       
+       m->saveNextLabel = "";
 }
-
 /***********************************************************************/
 
-
 InputData::~InputData(){
        fileHandle.close();
-       globaldata = GlobalData::getInstance();
-       globaldata->saveNextLabel = "";
-//     delete output;
-       
+       m->saveNextLabel = "";
 }
 
 /***********************************************************************/
@@ -38,7 +32,6 @@ InputData::~InputData(){
 InputData::InputData(string fName, string orderFileName, string f) : format(f){
        try {
                m = MothurOut::getInstance();
-               globaldata = GlobalData::getInstance();
                ifstream ofHandle;
                m->openInputFile(orderFileName, ofHandle);
                string name;
@@ -54,6 +47,8 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){
                ofHandle.close();
        
                m->openInputFile(fName, fileHandle);
+               m->saveNextLabel = "";
+               
        }
        catch(exception& e) {
                m->errorOut(e, "InputData", "InputData");
@@ -298,7 +293,7 @@ OrderVector* InputData::getOrderVector(){
                        else if(format == "sabund"){
                                input = new SAbundVector(fileHandle);
                        }
-                       
+                                               
                        m->gobble(fileHandle);
                        
                        output = new OrderVector();     
@@ -400,7 +395,7 @@ OrderVector* InputData::getOrderVector(string label){
                                }
 
                        }
-                       
+                                               
                        in.close();             
 
                        output = new OrderVector();
@@ -431,6 +426,7 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
                                }
                        }else if (format == "shared") {
                                SharedList = new SharedListVector(fileHandle);
+                               
                                if (SharedList != NULL) {
                                        return SharedList->getSharedRAbundVector();
                                }
@@ -455,7 +451,7 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
                string  thisLabel;
                
                m->openInputFile(filename, in);
-               globaldata->saveNextLabel = "";
+               m->saveNextLabel = "";
        
                if(in){
                        if (format == "sharedfile")  {
@@ -481,6 +477,7 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
                                while (in.eof() != true) {
                                        
                                        SharedList = new SharedListVector(in);
+                                       
                                        if (SharedList != NULL) {
                                                thisLabel = SharedList->getLabel();
                                                //if you are at the last label
@@ -519,6 +516,15 @@ vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(){
                                if (SharedRelAbund != NULL) {
                                        return SharedRelAbund->getSharedRAbundFloatVectors();
                                }
+                       }else if (format == "sharedfile")  {
+                               SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle);
+                               if (SharedRAbund != NULL) {
+                                       vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors(); 
+                                       vector<SharedRAbundFloatVector*> lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup); 
+                                       for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
+                                       return lookupFloat;  
+                               }
+                                               
                        }
                        m->gobble(fileHandle);
                }
@@ -540,10 +546,10 @@ vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string l
                string  thisLabel;
                
                m->openInputFile(filename, in);
-               globaldata->saveNextLabel = "";
+               m->saveNextLabel = "";
                
                if(in){
-                       if (format == "sharedfile")  {
+                       if (format == "relabund")  {
                                while (in.eof() != true) {
                                        
                                        SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in);
@@ -560,8 +566,32 @@ vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string l
                                        }else{  break;  }
                                        m->gobble(in);
                                }
-                       }
+                       }else if (format == "sharedfile")  {
+                               while (in.eof() != true) {
+                                       
+                                       SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in);
+                                       if (SharedRAbund != NULL) {
+                                               thisLabel = SharedRAbund->getLabel();
+                                               
+                                               //if you are at the last label
+                                               if (thisLabel == label) {  
+                                                       in.close(); 
+                                                       vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors(); 
+                                                       vector<SharedRAbundFloatVector*> lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup); 
+                                                       for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
+                                                       return lookupFloat;  
+                                               }else {
+                                                       //so you don't loose this memory
+                                                       vector<SharedRAbundVector*> lookup = SharedRAbund->getSharedRAbundVectors(); 
+                                                       for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear();
+                                                       delete SharedRAbund;
+                                               }
+                                       }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);
@@ -593,8 +623,7 @@ SAbundVector* InputData::getSAbundVector(){
                        }
                        else if(format == "sabund"){
                                input = new SAbundVector(fileHandle);
-                       }
-                                       
+                       }                                       
                        m->gobble(fileHandle);
 
                        sabund = new SAbundVector();
@@ -733,7 +762,7 @@ RAbundVector* InputData::getRAbundVector(){
                        else if(format == "sabund"){
                                input = new SAbundVector(fileHandle);
                        }
-                                       
+                       
                        m->gobble(fileHandle);
 
                        rabund = new RAbundVector();
@@ -833,7 +862,8 @@ RAbundVector* InputData::getRAbundVector(string label){
                                        
                                }
 
-                       }
+                       }                       
+                       
                        
                        in.close();