X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=inputdata.cpp;h=c9142b7a356de09f0fddd89ae5f415993f4795c3;hb=1ef03d78c36b105e87165ad1ebc9af29cd6144b7;hp=5d1542739b0b0b6d6e730a5e84654468e3ca819f;hpb=e99751591aa21705e58edda87383457b9738dd9e;p=mothur.git diff --git a/inputdata.cpp b/inputdata.cpp index 5d15427..c9142b7 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -16,21 +16,15 @@ 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"); @@ -88,6 +83,7 @@ ListVector* InputData::getListVector(string label){ ifstream in; string thisLabel; m->openInputFile(filename, in); + m->saveNextLabel = ""; if(in){ @@ -124,6 +120,7 @@ ListVector* InputData::getListVector(string label, bool resetFP){ string thisLabel; fileHandle.clear(); fileHandle.seekg(0); + m->saveNextLabel = ""; if(fileHandle){ @@ -244,6 +241,7 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){ ifstream in; string thisLabel; m->openInputFile(filename, in); + m->saveNextLabel = ""; if(in){ @@ -298,7 +296,7 @@ OrderVector* InputData::getOrderVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - + m->gobble(fileHandle); output = new OrderVector(); @@ -326,7 +324,7 @@ OrderVector* InputData::getOrderVector(string label){ if(in){ if((format == "list") || (format == "listorder")) { - + m->saveNextLabel = ""; while (in.eof() != true) { input = new ListVector(in); @@ -340,7 +338,7 @@ OrderVector* InputData::getOrderVector(string label){ } } else if (format == "shared") { - + m->saveNextLabel = ""; while (in.eof() != true) { input = new SharedListVector(in); @@ -400,7 +398,7 @@ OrderVector* InputData::getOrderVector(string label){ } } - + in.close(); output = new OrderVector(); @@ -431,6 +429,7 @@ vector InputData::getSharedRAbundVectors(){ } }else if (format == "shared") { SharedList = new SharedListVector(fileHandle); + if (SharedList != NULL) { return SharedList->getSharedRAbundVector(); } @@ -455,7 +454,7 @@ vector InputData::getSharedRAbundVectors(string label){ string thisLabel; m->openInputFile(filename, in); - globaldata->saveNextLabel = ""; + m->saveNextLabel = ""; if(in){ if (format == "sharedfile") { @@ -481,6 +480,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 @@ -519,6 +519,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); } @@ -540,7 +549,7 @@ vector InputData::getSharedRAbundFloatVectors(string l string thisLabel; m->openInputFile(filename, in); - globaldata->saveNextLabel = ""; + m->saveNextLabel = ""; if(in){ if (format == "relabund") { @@ -560,8 +569,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); @@ -593,8 +626,7 @@ SAbundVector* InputData::getSAbundVector(){ } else if(format == "sabund"){ input = new SAbundVector(fileHandle); - } - + } m->gobble(fileHandle); sabund = new SAbundVector(); @@ -621,7 +653,7 @@ SAbundVector* InputData::getSAbundVector(string label){ if(in){ if (format == "list") { - + m->saveNextLabel = ""; while (in.eof() != true) { input = new ListVector(in); @@ -635,7 +667,7 @@ SAbundVector* InputData::getSAbundVector(string label){ } } else if (format == "shared") { - + m->saveNextLabel = ""; while (in.eof() != true) { input = new SharedListVector(in); @@ -733,7 +765,7 @@ RAbundVector* InputData::getRAbundVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - + m->gobble(fileHandle); rabund = new RAbundVector(); @@ -760,6 +792,7 @@ RAbundVector* InputData::getRAbundVector(string label){ if(in){ if (format == "list") { + m->saveNextLabel = ""; while (in.eof() != true) { @@ -774,6 +807,7 @@ RAbundVector* InputData::getRAbundVector(string label){ } } else if (format == "shared") { + m->saveNextLabel = ""; while (in.eof() != true) { @@ -833,7 +867,8 @@ RAbundVector* InputData::getRAbundVector(string label){ } - } + } + in.close();