X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=inputdata.cpp;h=8b1829a3db697df21b3d0f64bf6be6cfea15c536;hb=bd27c2b0612942815b7417c79f7ee41f669a2a34;hp=8e54ab787c683535dd132caf0881aab3399945b9;hpb=74844a60d80c6dd06e3fb02ee9b928424f9019b0;p=mothur.git diff --git a/inputdata.cpp b/inputdata.cpp index 8e54ab7..8b1829a 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -16,18 +16,15 @@ InputData::InputData(string fName, string f) : format(f){ m = MothurOut::getInstance(); - openInputFile(fName, fileHandle); + m->openInputFile(fName, fileHandle); filename = fName; - + m->saveNextLabel = ""; } - /***********************************************************************/ - InputData::~InputData(){ fileHandle.close(); -// delete output; - + m->saveNextLabel = ""; } /***********************************************************************/ @@ -36,7 +33,7 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){ try { m = MothurOut::getInstance(); ifstream ofHandle; - openInputFile(orderFileName, ofHandle); + m->openInputFile(orderFileName, ofHandle); string name; int count = 0; @@ -45,11 +42,13 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){ ofHandle >> name; orderMap[name] = count; count++; - gobble(ofHandle); + m->gobble(ofHandle); } ofHandle.close(); - openInputFile(fName, fileHandle); + m->openInputFile(fName, fileHandle); + m->saveNextLabel = ""; + } catch(exception& e) { m->errorOut(e, "InputData", "InputData"); @@ -60,12 +59,12 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){ ListVector* InputData::getListVector(){ try { - if(fileHandle){ + if(!fileHandle.eof()){ if(format == "list") { list = new ListVector(fileHandle); }else{ list = NULL; } - gobble(fileHandle); + m->gobble(fileHandle); return list; } else{ @@ -79,12 +78,11 @@ ListVector* InputData::getListVector(){ } /***********************************************************************/ - ListVector* InputData::getListVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ @@ -99,7 +97,7 @@ ListVector* InputData::getListVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete list; } - gobble(in); + m->gobble(in); } }else{ list = NULL; } @@ -115,7 +113,40 @@ ListVector* InputData::getListVector(string label){ exit(1); } } +/***********************************************************************/ +ListVector* InputData::getListVector(string label, bool resetFP){ + try { + string thisLabel; + fileHandle.clear(); + fileHandle.seekg(0); + + if(fileHandle){ + if (format == "list") { + + while (fileHandle.eof() != true) { + + list = new ListVector(fileHandle); m->gobble(fileHandle); + thisLabel = list->getLabel(); + + //if you are at the last label + if (thisLabel == label) { break; } + //so you don't loose this memory + else { delete list; } + } + }else{ list = NULL; } + + return list; + } + else{ + return NULL; + } + } + catch(exception& e) { + m->errorOut(e, "InputData", "getListVector"); + exit(1); + } +} /***********************************************************************/ @@ -126,7 +157,7 @@ SharedListVector* InputData::getSharedListVector(){ SharedList = new SharedListVector(fileHandle); }else{ SharedList = NULL; } - gobble(fileHandle); + m->gobble(fileHandle); return SharedList; } else{ @@ -144,7 +175,7 @@ SharedListVector* InputData::getSharedListVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ @@ -159,7 +190,7 @@ SharedListVector* InputData::getSharedListVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete SharedList; } - gobble(in); + m->gobble(in); } }else{ SharedList = NULL; } @@ -188,7 +219,7 @@ SharedOrderVector* InputData::getSharedOrderVector(){ SharedOrder = new SharedOrderVector(fileHandle); }else{ SharedOrder = NULL; } - gobble(fileHandle); + m->gobble(fileHandle); return SharedOrder; }else{ @@ -207,7 +238,7 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ @@ -222,7 +253,7 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete SharedOrder; } - gobble(in); + m->gobble(in); } }else{ SharedOrder = NULL; } @@ -262,8 +293,8 @@ OrderVector* InputData::getOrderVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - - gobble(fileHandle); + + m->gobble(fileHandle); output = new OrderVector(); *output = (input->getOrderVector()); @@ -286,7 +317,7 @@ OrderVector* InputData::getOrderVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if((format == "list") || (format == "listorder")) { @@ -300,7 +331,7 @@ OrderVector* InputData::getOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } else if (format == "shared") { @@ -314,7 +345,7 @@ OrderVector* InputData::getOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -329,7 +360,7 @@ OrderVector* InputData::getOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -344,7 +375,7 @@ OrderVector* InputData::getOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -359,12 +390,12 @@ OrderVector* InputData::getOrderVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } - + in.close(); output = new OrderVector(); @@ -395,11 +426,12 @@ vector InputData::getSharedRAbundVectors(){ } }else if (format == "shared") { SharedList = new SharedListVector(fileHandle); + if (SharedList != NULL) { return SharedList->getSharedRAbundVector(); } } - gobble(fileHandle); + m->gobble(fileHandle); } //this is created to signal to calling function that the input file is at eof @@ -418,8 +450,9 @@ vector InputData::getSharedRAbundVectors(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); - + m->openInputFile(filename, in); + m->saveNextLabel = ""; + if(in){ if (format == "sharedfile") { while (in.eof() != true) { @@ -427,6 +460,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 { @@ -436,13 +470,14 @@ vector InputData::getSharedRAbundVectors(string label){ delete SharedRAbund; } }else{ break; } - gobble(in); + m->gobble(in); } }else if (format == "shared") { while (in.eof() != true) { SharedList = new SharedListVector(in); + if (SharedList != NULL) { thisLabel = SharedList->getLabel(); //if you are at the last label @@ -452,7 +487,7 @@ vector InputData::getSharedRAbundVectors(string label){ delete SharedList; } }else{ break; } - gobble(in); + m->gobble(in); } @@ -471,7 +506,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); + m->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(){ @@ -491,9 +623,8 @@ SAbundVector* InputData::getSAbundVector(){ } else if(format == "sabund"){ input = new SAbundVector(fileHandle); - } - - gobble(fileHandle); + } + m->gobble(fileHandle); sabund = new SAbundVector(); *sabund = (input->getSAbundVector()); @@ -515,7 +646,7 @@ SAbundVector* InputData::getSAbundVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if (format == "list") { @@ -529,7 +660,7 @@ SAbundVector* InputData::getSAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } else if (format == "shared") { @@ -543,7 +674,7 @@ SAbundVector* InputData::getSAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -558,7 +689,7 @@ SAbundVector* InputData::getSAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -573,7 +704,7 @@ SAbundVector* InputData::getSAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -588,7 +719,7 @@ SAbundVector* InputData::getSAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } @@ -631,8 +762,8 @@ RAbundVector* InputData::getRAbundVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - - gobble(fileHandle); + + m->gobble(fileHandle); rabund = new RAbundVector(); *rabund = (input->getRAbundVector()); @@ -654,7 +785,7 @@ RAbundVector* InputData::getRAbundVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if (format == "list") { @@ -668,7 +799,7 @@ RAbundVector* InputData::getRAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } else if (format == "shared") { @@ -682,7 +813,7 @@ RAbundVector* InputData::getRAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -697,7 +828,7 @@ RAbundVector* InputData::getRAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -712,7 +843,7 @@ RAbundVector* InputData::getRAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } } @@ -727,11 +858,12 @@ RAbundVector* InputData::getRAbundVector(string label){ if (thisLabel == label) { break; } //so you don't loose this memory else { delete input; } - gobble(in); + m->gobble(in); } - } + } + in.close();