]> git.donarmstrong.com Git - mothur.git/blobdiff - inputdata.cpp
pca command
[mothur.git] / inputdata.cpp
index 5d71450ef60bb0fe5c972d6c38fe67565a5687e7..283fb7edc33856613612e10b0d293d0eea1f056d 100644 (file)
@@ -16,6 +16,7 @@
 
 InputData::InputData(string fName, string f) : format(f){
        m = MothurOut::getInstance();
+       globaldata = GlobalData::getInstance();
        m->openInputFile(fName, fileHandle);
        filename = fName;
        
@@ -37,6 +38,7 @@ 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;
@@ -453,7 +455,8 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
                string  thisLabel;
                
                m->openInputFile(filename, in);
-               
+               globaldata->saveNextLabel = "";
+       
                if(in){
                        if (format == "sharedfile")  {
                                while (in.eof() != true) {
@@ -461,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 {
@@ -515,6 +519,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);
                }
@@ -536,9 +549,10 @@ vector<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string l
                string  thisLabel;
                
                m->openInputFile(filename, in);
+               globaldata->saveNextLabel = "";
                
                if(in){
-                       if (format == "sharedfile")  {
+                       if (format == "relabund")  {
                                while (in.eof() != true) {
                                        
                                        SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in);
@@ -555,8 +569,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);