X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=inputdata.cpp;h=8b1829a3db697df21b3d0f64bf6be6cfea15c536;hp=7c9fbe9c0eeda1472e09ce03c80cd5853103833e;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=260ae19c36cb11a53ddc5a75b5e507f8dd8b31d6 diff --git a/inputdata.cpp b/inputdata.cpp index 7c9fbe9..8b1829a 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -18,16 +18,13 @@ InputData::InputData(string fName, string f) : format(f){ m = MothurOut::getInstance(); m->openInputFile(fName, fileHandle); filename = fName; - + m->saveNextLabel = ""; } - /***********************************************************************/ - InputData::~InputData(){ fileHandle.close(); -// delete output; - + m->saveNextLabel = ""; } /***********************************************************************/ @@ -50,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"); @@ -294,7 +293,7 @@ OrderVector* InputData::getOrderVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - + m->gobble(fileHandle); output = new OrderVector(); @@ -396,7 +395,7 @@ OrderVector* InputData::getOrderVector(string label){ } } - + in.close(); output = new OrderVector(); @@ -427,6 +426,7 @@ vector InputData::getSharedRAbundVectors(){ } }else if (format == "shared") { SharedList = new SharedListVector(fileHandle); + if (SharedList != NULL) { return SharedList->getSharedRAbundVector(); } @@ -451,7 +451,8 @@ vector InputData::getSharedRAbundVectors(string label){ string thisLabel; m->openInputFile(filename, in); - + m->saveNextLabel = ""; + if(in){ if (format == "sharedfile") { while (in.eof() != true) { @@ -459,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 { @@ -475,6 +477,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 @@ -503,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(){ @@ -523,8 +623,7 @@ SAbundVector* InputData::getSAbundVector(){ } else if(format == "sabund"){ input = new SAbundVector(fileHandle); - } - + } m->gobble(fileHandle); sabund = new SAbundVector(); @@ -663,7 +762,7 @@ RAbundVector* InputData::getRAbundVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - + m->gobble(fileHandle); rabund = new RAbundVector(); @@ -763,7 +862,8 @@ RAbundVector* InputData::getRAbundVector(string label){ } - } + } + in.close();