X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=inputdata.cpp;h=c9142b7a356de09f0fddd89ae5f415993f4795c3;hb=fefd5ee1517abd3bc38b469cb2dffc85a1571c7e;hp=c2f4e4e63347ce62b818617fd4e05da629a84972;hpb=016a30dacbe75869aef5fdb58d2d1bf9eb8f9b33;p=mothur.git diff --git a/inputdata.cpp b/inputdata.cpp index c2f4e4e..c9142b7 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -15,28 +15,25 @@ /***********************************************************************/ InputData::InputData(string fName, string f) : format(f){ - - openInputFile(fName, fileHandle); + m = MothurOut::getInstance(); + m->openInputFile(fName, fileHandle); filename = fName; - + m->saveNextLabel = ""; } - /***********************************************************************/ - InputData::~InputData(){ fileHandle.close(); -// delete output; - + m->saveNextLabel = ""; } /***********************************************************************/ 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,31 +42,29 @@ 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) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "InputData"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function InputData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ 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{ @@ -77,22 +72,18 @@ ListVector* InputData::getListVector(){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getListVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ - ListVector* InputData::getListVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); + m->saveNextLabel = ""; if(in){ @@ -107,9 +98,9 @@ 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; } in.close(); return list; @@ -119,15 +110,45 @@ ListVector* InputData::getListVector(string label){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getListVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } +/***********************************************************************/ +ListVector* InputData::getListVector(string label, bool resetFP){ + try { + string thisLabel; + fileHandle.clear(); + fileHandle.seekg(0); + m->saveNextLabel = ""; + + 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); + } +} /***********************************************************************/ @@ -136,9 +157,9 @@ SharedListVector* InputData::getSharedListVector(){ if(fileHandle){ if (format == "shared") { SharedList = new SharedListVector(fileHandle); - } + }else{ SharedList = NULL; } - gobble(fileHandle); + m->gobble(fileHandle); return SharedList; } else{ @@ -146,13 +167,9 @@ SharedListVector* InputData::getSharedListVector(){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getSharedListVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -160,7 +177,7 @@ SharedListVector* InputData::getSharedListVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ @@ -175,10 +192,10 @@ 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; } in.close(); return SharedList; @@ -188,13 +205,9 @@ SharedListVector* InputData::getSharedListVector(string label){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getSharedListVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getSharedListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } @@ -206,9 +219,9 @@ SharedOrderVector* InputData::getSharedOrderVector(){ if(fileHandle){ if (format == "sharedfile") { SharedOrder = new SharedOrderVector(fileHandle); - } + }else{ SharedOrder = NULL; } - gobble(fileHandle); + m->gobble(fileHandle); return SharedOrder; }else{ @@ -216,13 +229,9 @@ SharedOrderVector* InputData::getSharedOrderVector(){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getSharedOrderVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -231,7 +240,8 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){ try { ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); + m->saveNextLabel = ""; if(in){ @@ -246,10 +256,10 @@ 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; } in.close(); return SharedOrder; @@ -259,13 +269,9 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getSharedOrderVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getSharedOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } @@ -290,11 +296,12 @@ OrderVector* InputData::getOrderVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - - gobble(fileHandle); - output = new OrderVector(); - *output = (input->getOrderVector()); + + m->gobble(fileHandle); + output = new OrderVector(); + *output = (input->getOrderVector()); + return output; } else{ @@ -302,13 +309,9 @@ OrderVector* InputData::getOrderVector(){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getOrderVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -317,11 +320,11 @@ OrderVector* InputData::getOrderVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if((format == "list") || (format == "listorder")) { - + m->saveNextLabel = ""; while (in.eof() != true) { input = new ListVector(in); @@ -331,11 +334,11 @@ 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") { - + m->saveNextLabel = ""; while (in.eof() != true) { input = new SharedListVector(in); @@ -345,7 +348,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); } } @@ -360,7 +363,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); } } @@ -375,7 +378,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); } } @@ -390,12 +393,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(); @@ -409,13 +412,9 @@ OrderVector* InputData::getOrderVector(string label){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getOrderVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getOrderVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -430,11 +429,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 @@ -443,13 +443,9 @@ vector InputData::getSharedRAbundVectors(){ } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getSharedRAbundVectors"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ vector InputData::getSharedRAbundVectors(string label){ @@ -457,8 +453,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) { @@ -466,6 +463,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 { @@ -475,13 +473,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 @@ -491,7 +490,7 @@ vector InputData::getSharedRAbundVectors(string label){ delete SharedList; } }else{ break; } - gobble(in); + m->gobble(in); } @@ -505,16 +504,109 @@ vector InputData::getSharedRAbundVectors(string label){ } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getSharedRAbundVectors"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getSharedRAbundVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } - +/***********************************************************************/ +//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(){ @@ -534,9 +626,8 @@ SAbundVector* InputData::getSAbundVector(){ } else if(format == "sabund"){ input = new SAbundVector(fileHandle); - } - - gobble(fileHandle); + } + m->gobble(fileHandle); sabund = new SAbundVector(); *sabund = (input->getSAbundVector()); @@ -548,13 +639,9 @@ SAbundVector* InputData::getSAbundVector(){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getSAbundVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ SAbundVector* InputData::getSAbundVector(string label){ @@ -562,11 +649,11 @@ SAbundVector* InputData::getSAbundVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if (format == "list") { - + m->saveNextLabel = ""; while (in.eof() != true) { input = new ListVector(in); @@ -576,11 +663,11 @@ 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") { - + m->saveNextLabel = ""; while (in.eof() != true) { input = new SharedListVector(in); @@ -590,7 +677,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 +692,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 +707,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); } } @@ -635,7 +722,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); } @@ -654,13 +741,9 @@ SAbundVector* InputData::getSAbundVector(string label){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getSAbundVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getSAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -682,8 +765,8 @@ RAbundVector* InputData::getRAbundVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - - gobble(fileHandle); + + m->gobble(fileHandle); rabund = new RAbundVector(); *rabund = (input->getRAbundVector()); @@ -695,13 +778,9 @@ RAbundVector* InputData::getRAbundVector(){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getRAbundVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ RAbundVector* InputData::getRAbundVector(string label){ @@ -709,10 +788,11 @@ RAbundVector* InputData::getRAbundVector(string label){ ifstream in; string thisLabel; - openInputFile(filename, in); + m->openInputFile(filename, in); if(in){ if (format == "list") { + m->saveNextLabel = ""; while (in.eof() != true) { @@ -723,10 +803,11 @@ 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") { + m->saveNextLabel = ""; while (in.eof() != true) { @@ -737,7 +818,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); } } @@ -752,7 +833,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); } } @@ -767,7 +848,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); } } @@ -782,11 +863,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(); @@ -800,13 +882,9 @@ RAbundVector* InputData::getRAbundVector(string label){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the InputData class Function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "InputData", "getRAbundVector"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the InputData class function getRAbundVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/