X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=inputdata.cpp;h=5d1542739b0b0b6d6e730a5e84654468e3ca819f;hb=a5af3313f0221a8b41aa362d72eadb60a4dd6e27;hp=65685d6a7e13c09f6563ebb3c2ea3f78dd3fd937;hpb=725a3d4ff2442c79bfde0a75ed3e0904edcf03b7;p=mothur.git diff --git a/inputdata.cpp b/inputdata.cpp index 65685d6..5d15427 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -16,7 +16,8 @@ InputData::InputData(string fName, string f) : format(f){ m = MothurOut::getInstance(); - openInputFile(fName, fileHandle); + 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,8 +38,9 @@ InputData::~InputData(){ InputData::InputData(string fName, string orderFileName, string f) : format(f){ try { m = MothurOut::getInstance(); + globaldata = GlobalData::getInstance(); ifstream ofHandle; - openInputFile(orderFileName, ofHandle); + m->openInputFile(orderFileName, ofHandle); string name; int count = 0; @@ -45,11 +49,11 @@ 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); } catch(exception& e) { m->errorOut(e, "InputData", "InputData"); @@ -65,7 +69,7 @@ ListVector* InputData::getListVector(){ list = new ListVector(fileHandle); }else{ list = NULL; } - gobble(fileHandle); + m->gobble(fileHandle); return list; } else{ @@ -83,7 +87,7 @@ ListVector* InputData::getListVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ @@ -98,7 +102,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; } @@ -127,7 +131,7 @@ ListVector* InputData::getListVector(string label, bool resetFP){ while (fileHandle.eof() != true) { - list = new ListVector(fileHandle); gobble(fileHandle); + list = new ListVector(fileHandle); m->gobble(fileHandle); thisLabel = list->getLabel(); //if you are at the last label @@ -158,7 +162,7 @@ SharedListVector* InputData::getSharedListVector(){ SharedList = new SharedListVector(fileHandle); }else{ SharedList = NULL; } - gobble(fileHandle); + m->gobble(fileHandle); return SharedList; } else{ @@ -176,7 +180,7 @@ SharedListVector* InputData::getSharedListVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ @@ -191,7 +195,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; } @@ -220,7 +224,7 @@ SharedOrderVector* InputData::getSharedOrderVector(){ SharedOrder = new SharedOrderVector(fileHandle); }else{ SharedOrder = NULL; } - gobble(fileHandle); + m->gobble(fileHandle); return SharedOrder; }else{ @@ -239,7 +243,7 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ @@ -254,7 +258,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; } @@ -295,7 +299,7 @@ OrderVector* InputData::getOrderVector(){ input = new SAbundVector(fileHandle); } - gobble(fileHandle); + m->gobble(fileHandle); output = new OrderVector(); *output = (input->getOrderVector()); @@ -318,7 +322,7 @@ OrderVector* InputData::getOrderVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if((format == "list") || (format == "listorder")) { @@ -332,7 +336,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") { @@ -346,7 +350,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); } } @@ -361,7 +365,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); } } @@ -376,7 +380,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); } } @@ -391,7 +395,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); } @@ -431,7 +435,7 @@ vector InputData::getSharedRAbundVectors(){ return SharedList->getSharedRAbundVector(); } } - gobble(fileHandle); + m->gobble(fileHandle); } //this is created to signal to calling function that the input file is at eof @@ -450,8 +454,9 @@ vector InputData::getSharedRAbundVectors(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); - + 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 { @@ -468,7 +474,7 @@ vector InputData::getSharedRAbundVectors(string label){ delete SharedRAbund; } }else{ break; } - gobble(in); + m->gobble(in); } }else if (format == "shared") { @@ -484,7 +490,7 @@ vector InputData::getSharedRAbundVectors(string label){ delete SharedList; } }else{ break; } - gobble(in); + m->gobble(in); } @@ -503,7 +509,71 @@ 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(); + } + } + 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); + } + } + } + + //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(){ @@ -525,7 +595,7 @@ SAbundVector* InputData::getSAbundVector(){ input = new SAbundVector(fileHandle); } - gobble(fileHandle); + m->gobble(fileHandle); sabund = new SAbundVector(); *sabund = (input->getSAbundVector()); @@ -547,7 +617,7 @@ SAbundVector* InputData::getSAbundVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if (format == "list") { @@ -561,7 +631,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") { @@ -575,7 +645,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); } } @@ -590,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); } } @@ -605,7 +675,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); } } @@ -620,7 +690,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); } @@ -664,7 +734,7 @@ RAbundVector* InputData::getRAbundVector(){ input = new SAbundVector(fileHandle); } - gobble(fileHandle); + m->gobble(fileHandle); rabund = new RAbundVector(); *rabund = (input->getRAbundVector()); @@ -686,7 +756,7 @@ RAbundVector* InputData::getRAbundVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if (format == "list") { @@ -700,7 +770,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") { @@ -714,7 +784,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); } } @@ -729,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); } } @@ -744,7 +814,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); } } @@ -759,7 +829,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); }