X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=inputdata.cpp;h=283fb7edc33856613612e10b0d293d0eea1f056d;hb=37eac2026d91179acda0494c4dcca22f176551b9;hp=7c9fbe9c0eeda1472e09ce03c80cd5853103833e;hpb=260ae19c36cb11a53ddc5a75b5e507f8dd8b31d6;p=mothur.git diff --git a/inputdata.cpp b/inputdata.cpp index 7c9fbe9..283fb7e 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -16,6 +16,7 @@ InputData::InputData(string fName, string f) : format(f){ 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; } @@ -35,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; @@ -451,7 +455,8 @@ vector InputData::getSharedRAbundVectors(string label){ string thisLabel; m->openInputFile(filename, in); - + globaldata->saveNextLabel = ""; + if(in){ if (format == "sharedfile") { while (in.eof() != true) { @@ -459,6 +464,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 { @@ -503,7 +509,104 @@ vector InputData::getSharedRAbundVectors(string label){ } } - +/***********************************************************************/ +//this is used when you don't need the order vector +vector InputData::getSharedRAbundFloatVectors(){ + try { + if(fileHandle){ + if (format == "relabund") { + SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(fileHandle); + 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); + } + + //this is created to signal to calling function that the input file is at eof + vector null; null.push_back(NULL); + return null; + + } + catch(exception& e) { + m->errorOut(e, "InputData", "getSharedRAbundFloatVectors"); + exit(1); + } +} +/***********************************************************************/ +vector InputData::getSharedRAbundFloatVectors(string label){ + try { + ifstream in; + string thisLabel; + + m->openInputFile(filename, in); + globaldata->saveNextLabel = ""; + + if(in){ + if (format == "relabund") { + 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 lookup = SharedRelAbund->getSharedRAbundFloatVectors(); + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete SharedRelAbund; + } + }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); + in.close(); + return null; + + } + catch(exception& e) { + m->errorOut(e, "InputData", "getSharedRAbundFloatVectors"); + exit(1); + } +} /***********************************************************************/ SAbundVector* InputData::getSAbundVector(){