X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=inputdata.cpp;h=ac215ca99438fce1b19416c93942d8c5ef51c6a3;hb=1a1ed6dda1d655ff006459f15c712f057c93ddaf;hp=5d71450ef60bb0fe5c972d6c38fe67565a5687e7;hpb=a76d81690125ca57d7f602ac93abad75cf9796c2;p=mothur.git diff --git a/inputdata.cpp b/inputdata.cpp index 5d71450..ac215ca 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -18,17 +18,15 @@ InputData::InputData(string fName, string f) : format(f){ m = MothurOut::getInstance(); m->openInputFile(fName, fileHandle); filename = fName; + m->saveNextLabel = ""; + } - /***********************************************************************/ - InputData::~InputData(){ fileHandle.close(); - globaldata = GlobalData::getInstance(); - globaldata->saveNextLabel = ""; -// delete output; + m->saveNextLabel = ""; } @@ -52,6 +50,7 @@ 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"); @@ -296,7 +295,7 @@ OrderVector* InputData::getOrderVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - + m->gobble(fileHandle); output = new OrderVector(); @@ -398,7 +397,7 @@ OrderVector* InputData::getOrderVector(string label){ } } - + in.close(); output = new OrderVector(); @@ -429,6 +428,7 @@ vector InputData::getSharedRAbundVectors(){ } }else if (format == "shared") { SharedList = new SharedListVector(fileHandle); + if (SharedList != NULL) { return SharedList->getSharedRAbundVector(); } @@ -453,7 +453,8 @@ vector InputData::getSharedRAbundVectors(string label){ string thisLabel; m->openInputFile(filename, in); - + m->saveNextLabel = ""; + if(in){ if (format == "sharedfile") { while (in.eof() != true) { @@ -461,6 +462,7 @@ vector 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 { @@ -477,6 +479,7 @@ vector 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 @@ -515,6 +518,15 @@ vector InputData::getSharedRAbundFloatVectors(){ if (SharedRelAbund != NULL) { return SharedRelAbund->getSharedRAbundFloatVectors(); } + }else if (format == "sharedfile") { + SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle); + if (SharedRAbund != NULL) { + vector lookup = SharedRAbund->getSharedRAbundVectors(); + vector lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear(); + return lookupFloat; + } + } m->gobble(fileHandle); } @@ -536,9 +548,10 @@ vector InputData::getSharedRAbundFloatVectors(string l string thisLabel; m->openInputFile(filename, in); + m->saveNextLabel = ""; if(in){ - if (format == "sharedfile") { + if (format == "relabund") { while (in.eof() != true) { SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in); @@ -555,8 +568,32 @@ vector 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 lookup = SharedRAbund->getSharedRAbundVectors(); + vector 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 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 null; null.push_back(NULL); @@ -588,8 +625,7 @@ SAbundVector* InputData::getSAbundVector(){ } else if(format == "sabund"){ input = new SAbundVector(fileHandle); - } - + } m->gobble(fileHandle); sabund = new SAbundVector(); @@ -728,7 +764,7 @@ RAbundVector* InputData::getRAbundVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - + m->gobble(fileHandle); rabund = new RAbundVector(); @@ -828,7 +864,8 @@ RAbundVector* InputData::getRAbundVector(string label){ } - } + } + in.close();